|
1 | 1 | # Changelog
|
2 | 2 |
|
3 |
| -### 2.0.0 - Less boilerplate & full `pytest` alignment ! |
| 3 | +### 2.0.0 - Less boilerplate & full `pytest` alignment |
4 | 4 |
|
5 |
| -**Case functions** |
| 5 | +I am very pleased to announce this new version of `pytest-cases`, providing a lot of **major** improvements. Creating powerful and complex test suites have never been so easy and intuitive ! |
6 | 6 |
|
7 |
| - - New `@case(id=None, tags=(), marks=())` decorator to replace `@case_name`, `@case_tags` and `@test_target` (all deprecated): a single simple way to customize all aspects of a case function. Also, `target` disappears from the picture as it was just a tag like others - this could be misleading. |
| 7 | +Below is a complete list of changes, but the user guide has also been updated accordingly so feel free to [have a look](index.md) to get a complete example-based walkthrough. |
8 | 8 |
|
9 |
| - - `@cases_generator` is now deprecated and replaced with `@parametrize` : now, cases can be parametrized exactly the same way than tests. This includes the ability to put marks on the whole or on some specific parameter values. `@parametrize_plus` has been renamed `@parametrize` for readability. It was also improved in order to support the alternate parametrization mode that was previously offered by `@cases_generator`. That way, users will be able to choose the style of their choice. Fixes [#57](https://github.com/smarie/python-pytest-cases/issues/57) and [#106](https://github.com/smarie/python-pytest-cases/issues/106). |
10 |
| - |
11 |
| - - Since `@cases_generat`Marks can now |
12 |
| - |
13 |
| - - Now case functions can require fixtures ! In that case they will be transformed into fixtures and injected as `fixture_ref` in the parametrization. Fixes [#56](https://github.com/smarie/python-pytest-cases/issues/56). |
14 | 9 |
|
| 10 | +**A/ More powerful and flexible cases collection** |
15 | 11 |
|
16 |
| -**Test functions** |
| 12 | +New [`@parametrize_with_cases`](./api_reference.md#parametrize_with_cases) decorator to replace `@cases_data` (deprecated). |
17 | 13 |
|
18 |
| -New `@parametrize_with_cases(argnames, cases, ...)` decorator to replace `@cases_data` (deprecated): |
19 |
| - |
20 |
| - - Aligned with `pytest` behaviour: |
| 14 | + 1. Aligned with `pytest`: |
21 | 15 |
|
22 |
| - - now `argnames` can contain several names, and the cases are unpacked automatically. **Less boilerplate code**: no need to perform a `case.get()` in the test anymore ! |
| 16 | + - now `argnames` can contain several names, and the case functions are **automatically unpacked** into it. You don't need to perform a `case.get()` in the test anymore ! |
23 | 17 |
|
24 | 18 | @parametrize_with_cases("a,b")
|
25 | 19 | def test_foo(a, b):
|
26 | 20 | # use a and b directly !
|
27 | 21 | ...
|
28 | 22 |
|
29 |
| - |
30 | 23 | - cases are unpacked at test *setup* time, so *the clock does not run while the case is created* - in case you use `pytest-harvest` to collect the timings.
|
31 | 24 |
|
32 | 25 | - `@parametrize_with_cases` can be used on test functions *as well as fixture functions* (it was already the case in v1)
|
33 | 26 |
|
34 | 27 |
|
35 |
| - - **A single `cases` argument** to indicate the cases, wherever they come from: |
| 28 | + 2. Easier to configure: |
| 29 | + |
| 30 | + - the decorator now has a single `cases` argument to indicate the cases, wherever they come from (no `module` argument anymore) |
36 | 31 |
|
37 |
| - - Default (`cases=AUTO`) *automatically looks for cases in the associated case module* named `test_xxx_cases.py`. Users can easily switch to alternate pattern `cases_xxx.py` with `cases=AUTO2`. Fixes [#91](https://github.com/smarie/python-pytest-cases/issues/91). |
| 32 | + - default (`cases=AUTO`) *automatically looks for cases in the associated case module* named `test_xxx_cases.py`. Users can easily switch to alternate pattern `cases_xxx.py` with `cases=AUTO2`. Fixes [#91](https://github.com/smarie/python-pytest-cases/issues/91). |
38 | 33 |
|
39 |
| - - *Cases can sit inside a class*, which makes it much more convenient to organize when they sit in the same file than the tests. Fixes [#93](https://github.com/smarie/python-pytest-cases/issues/93). |
| 34 | + - **cases can sit inside a class**, like [what you're used to do with `pytest`](https://docs.pytest.org/en/stable/getting-started.html#group-multiple-tests-in-a-class). This additional style makes it much more convenient to organize cases and associated them with tests, when cases sit in the same file than the tests. Fixes [#93](https://github.com/smarie/python-pytest-cases/issues/93). |
40 | 35 |
|
41 | 36 | - an explicit sequence can be provided, *it can mix all kind of sources*: functions, classes, modules, and *module names as strings* (even relative ones!).
|
42 | 37 |
|
43 | 38 | @parametrize_with_cases("a", cases=(CasesClass, '.my_extra_cases'))
|
44 | 39 | def test_foo(a):
|
45 | 40 | ...
|
46 | 41 |
|
47 |
| -**Misc / pytest goodies** |
48 | 42 |
|
49 |
| - - `parametrize_plus` now raises an explicit error message when the user makes a mistake with the argnames. Fixes [#105](https://github.com/smarie/python-pytest-cases/issues/105). |
| 43 | + 3. More powerful API for filtering: |
50 | 44 |
|
51 |
| - - `parametrize_plus` now provides an alternate way to pass argnames, argvalues and ids. Fixes [#106](https://github.com/smarie/python-pytest-cases/issues/106). |
| 45 | + - a new `prefix` argument (default `case_`) can be used to define case functions for various type of parameters: welcome `user_<id>`, `data_<id>`, `algo_<id>`, `model_<id>` ! Fixes [#108](https://github.com/smarie/python-pytest-cases/issues/108) |
| 46 | + |
| 47 | + - a new `glob` argument receiving a glob-like string can be used to further filter cases based on their names. For example you can distinguish `*_success` from `*_failure` case ids, so as to dispatch them to the appropriate positive or negative test. Fixes [#108](https://github.com/smarie/python-pytest-cases/issues/108) |
| 48 | + |
| 49 | + - finally you can still use `has_tag` and/or provide a `filter` callable, but now the callable will receive the case function, and this case function has a `f._pytestcase` attribute containing the id, tags and marks - it is therefore much easier to implement custom filtering. |
52 | 50 |
|
53 |
| - - New aliases for readability: `fixture` for `fixture_plus`, and`parametrize` for `parametrize_plus` (both aliases will coexist with the old names). Fixes [#107](https://github.com/smarie/python-pytest-cases/issues/107). |
54 | 51 |
|
55 |
| - - New pytest goodie `assert_exception` that can be used as a context manager. Fixes [#104](https://github.com/smarie/python-pytest-cases/issues/104). |
56 |
| - |
57 |
| - - More readable error messages when `lazy_value` does not return the same number of argvalues than expected by the `parametrize`. |
58 |
| - |
59 |
| - - Any error message associated to a `lazy_value` function call is not caught and hidden anymore but is emitted to the user. |
| 52 | +**B/ Easier-to-define case functions** |
| 53 | + |
| 54 | + - Case functions can start with different prefixes to denote different kind of data: e.g. `data_<id>`, `user_<id>`, `model_<id>`, etc. |
| 55 | + |
| 56 | + - Case functions can now be parametrized with [`@parametrize`](pytest_goodies.md#parametrize) or `@pytest.mark.parametrize`, just as in pytest ! This includes the ability to put [`pytest` marks](https://docs.pytest.org/en/stable/mark.html) on the whole case, or on some specific parameter values using [`pytest.param`](https://docs.pytest.org/en/stable/example/parametrize.html#set-marks-or-test-id-for-individual-parametrized-test). `@cases_generator` is therefore now deprecated but its alternate style for ids and arguments definition was preserved in `@parametrize`, see below. |
| 57 | + |
| 58 | + - Now case functions can require fixtures ! In that case they will be transformed into fixtures and injected as `fixture_ref` in the parametrization. Fixes [#56](https://github.com/smarie/python-pytest-cases/issues/56). |
| 59 | + |
| 60 | + - New single optional `@case(id=None, tags=(), marks=())` decorator to replace `@case_name` and `@case_tags` (deprecated): a single simple way to customize all aspects of a case function. Also, `@test_target` completely disappears from the picture as it was just a tag like others - this could be misleading. |
| 61 | + |
| 62 | + |
| 63 | +**C/ Misc / pytest goodies** |
| 64 | + |
| 65 | + - New aliases for readability: `@fixture` for `@fixture_plus`, and`@parametrize` for `@parametrize_plus` (both aliases will coexist with the old names). Fixes [#107](https://github.com/smarie/python-pytest-cases/issues/107). |
| 66 | + |
| 67 | + - `@parametrize` was improved in order to support the alternate parametrization mode that was previously offered by `@cases_generator`, see [api reference](api_reference.md#parametrize). That way, users will be able to choose the style of their choice. Fixes [#57](https://github.com/smarie/python-pytest-cases/issues/57) and [#106](https://github.com/smarie/python-pytest-cases/issues/106). |
| 68 | + |
| 69 | + - `@parametrize` now raises an explicit error message when the user makes a mistake with the argnames. Fixes [#105](https://github.com/smarie/python-pytest-cases/issues/105). |
| 70 | + |
| 71 | + - More readable error messages in `@parametrize` when `lazy_value` does not return the same number of argvalues than expected from the argnames. |
| 72 | + |
| 73 | + - Any error message associated to a `lazy_value` function call is not caught and hidden anymore but is emitted to the user, for easier debugging. |
60 | 74 |
|
61 | 75 | - Fixed issue with `lazy_value` when a single mark is passed in the constructor.
|
62 | 76 |
|
63 | 77 | - `lazy_value` used as a tuple for several arguments now have a correct id generated even in old pytest version 2.
|
| 78 | + |
| 79 | + - New pytest goodie `assert_exception` that can be used as a context manager. Fixes [#104](https://github.com/smarie/python-pytest-cases/issues/104). |
| 80 | + |
64 | 81 |
|
65 | 82 | ### 1.17.0 - `lazy_value` improvements + annoying warnings suppression
|
66 | 83 |
|
|
0 commit comments