Releases: smarie/python-pytest-cases
2.0.0 - Less boilerplate & full `pytest` alignment
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 !
Below is a complete list of changes, but the user guide has also been updated accordingly so feel free to have a look to get a complete example-based walkthrough.
A/ More powerful and flexible cases collection
New @parametrize_with_cases decorator to replace @cases_data (deprecated).
-
Aligned with
pytest:-
now
argnamescan contain several names, and the case functions are automatically unpacked into it. You don't need to perform acase.get()in the test anymore !@parametrize_with_cases("a,b") def test_foo(a, b): # use a and b directly ! ... -
cases are unpacked at test setup time, so the clock does not run while the case is created - in case you use
pytest-harvestto collect the timings. -
@parametrize_with_casescan be used on test functions as well as fixture functions (it was already the case in v1)
-
-
Easier to configure:
-
the decorator now has a single
casesargument to indicate the cases, wherever they come from (nomoduleargument anymore) -
default (
cases=AUTO) automatically looks for cases in the associated case module namedtest_xxx_cases.py. Users can easily switch to alternate patterncases_xxx.pywithcases=AUTO2. Fixes #91. -
cases can sit inside a class, like what you're used to do with
pytest. 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. -
an explicit sequence can be provided, it can mix all kind of sources: functions, classes, modules, and module names as strings (even relative ones!).
@parametrize_with_cases("a", cases=(CasesClass, '.my_extra_cases')) def test_foo(a): ...
-
-
More powerful API for filtering:
-
a new
prefixargument (defaultcase_) can be used to define case functions for various type of parameters: welcomeuser_<id>,data_<id>,algo_<id>,model_<id>! Fixes #108 -
a new
globargument receiving a glob-like string can be used to further filter cases based on their names. For example you can distinguish*_successfrom*_failurecase ids, so as to dispatch them to the appropriate positive or negative test. Fixes #108 -
finally you can still use
has_tagand/or provide afiltercallable, but now the callable will receive the case function, and this case function has af._pytestcaseattribute containing the id, tags and marks - it is therefore much easier to implement custom filtering.
-
B/ Easier-to-define case functions
-
Case functions can start with different prefixes to denote different kind of data: e.g.
data_<id>,user_<id>,model_<id>, etc. -
Case functions can now be parametrized with
@parametrizeor@pytest.mark.parametrize, just as in pytest ! This includes the ability to putpytestmarks on the whole case, or on some specific parameter values usingpytest.param.@cases_generatoris therefore now deprecated but its alternate style for ids and arguments definition was preserved in@parametrize, see below. -
Now case functions can require fixtures ! In that case they will be transformed into fixtures and injected as
fixture_refin the parametrization. Fixes #56. -
New single optional
@case(id=None, tags=(), marks=())decorator to replace@case_nameand@case_tags(deprecated): a single simple way to customize all aspects of a case function. Also,@test_targetcompletely disappears from the picture as it was just a tag like others - this could be misleading.
C/ Misc / pytest goodies
-
New aliases for readability:
@fixturefor@fixture_plus, and@parametrizefor@parametrize_plus(both aliases will coexist with the old names). Fixes #107. -
@parametrizewas improved in order to support the alternate parametrization mode that was previously offered by@cases_generator, see api reference. That way, users will be able to choose the style of their choice. Fixes #57 and #106. -
@parametrizenow raises an explicit error message when the user makes a mistake with the argnames. Fixes #105. -
More readable error messages in
@parametrizewhenlazy_valuedoes not return the same number of argvalues than expected from the argnames. -
Any error message associated to a
lazy_valuefunction call is not caught and hidden anymore but is emitted to the user, for easier debugging. -
Fixed issue with
lazy_valuewhen a single mark is passed in the constructor. -
lazy_valueused as a tuple for several arguments now have a correct id generated even in old pytest version 2. -
New pytest goodie
assert_exceptionthat can be used as a context manager. Fixes #104.
See documentation page for details.
1.17.0 - `lazy_value` improvements + annoying warnings suppression
-
lazy_valueare now resolved at pytestsetupstage, not pytestcallstage. This is important for execution time recorded in the reports (see alsopytest-harvestplugin). Fixes #102 -
A function used as a
lazy_valuecan now be marked with pytest marks. Fixes #99 -
A
lazy_valuenow has a nicer id when it is a partial. Fixes #97 -
Removed annoying
PytestUnknownMarkWarningwarning message when a mark was used on a case. Fixes #100
See documentation page for details.
1.16.0 - New `lazy_value` for parameters
- New marker
lazy_valueforparametrize_plus. Fixes #92
See documentation page for details.
1.15.0 - better `parametrize_plus` and smaller dependencies
-
Better support for
pytest.paraminparametrize_plusand also infixture_unionandfixture_param[s]. Improved corresponding ids. Fixed #79 and #86 -
New
@ignore_unuseddecorator to protect a fixture function from the "NOT_USED" case happening when the fixture is used in a fixture union. -
Removed
six,wraptandenum34dependencies -
(Internal) submodules reorganization for readability
-
(Internal) suppressed a lot of code quality warnings
See documentation page for details.
1.14.0 - bugfixes and hook feature
-
Fixed
idsprecedence order when usingpytest.mark.parametrizein afixture_plus. Fixed #87 -
Fixed issue with
fixture_unionwhen using the same fixture twice in it. Fixes #85 -
Added the possibility to pass a
hookfunction in all API where fixtures are created behind the scenes, so as to ease debugging and/or save fixtures (withstored_fixturefrom pytest harvest). Fixes #83 -
Fixture closures now support reordering when no unions are present. This suppressed the annoying warning "WARNING the new order is not taken into account !!" when it was not relevant. Fixes #81
See documentation page for details.
1.13.1 - packaging improvements
- packaging improvements: set the "universal wheel" flag to 1, and cleaned up the
setup.py. In particular removed dependency tosixfor setup and addedpy.typedfile. Fixes #78
See documentation page for details.
1.13.0 - `@cases_generator` default `names`
@cases_generator now has a default value for the names template, based on the parameters. Fixes #77.
See documentation page for details.
1.12.4 - Bugfix
Fixed ValueError when a product of unions was used on a test node, for example when two parametrize_plus using fixture_refs were used on the same fixture or test function. Fixed #76
See documentation page for details.
1.12.3 - Improved error messages
Improved error message when something that is not a fixture is used in unpack_fixture or fixture_union. Fixed #75
See documentation page for details.
1.12.2 - Warning fix
Fixed deprecation warning #74
See documentation page for details.