Separate test code from test cases in pytest.
BSD-3-CLAUSE License
Bot releases are visible (Hide)
Published by smarie almost 4 years ago
lazy_value
parameters are now cached by pytest node id only. So plugins can access the value without triggering an extra function call, but a new call is triggered for each pytest node, so as to prevent mutable object leakage across tests. Fixed #149 while ensuring no regression for #143.
The ids
argument of parametrize
now accepts a (possibly infinite) generator of ids, e.g. (f"foo{i}" for i in itertools.count()
), just as pytest
does. This was not always the case, inparticular when parametrizing a @fixture
. The ids
arguments of fixture_union
, param_fixture[s]
, etc. now also support this pattern. Fixed #148
See documentation page for details.
Published by smarie almost 4 years ago
glob
argument in @parametrize_with_cases
. Also made the implementation escape all regex special characters so that they can't be used. Finally a pattern should now match the entire case id (previously, a partial match would work if it was at the beginning of the string). One step towards #147
See documentation page for details.
Published by smarie almost 4 years ago
is_lazy
is now part of public API, and _LazyValue
now has a cache mechanism like _LazyTuple
. Fixes #143
@parametrize
: custom ids
are now correctly taken into account when a single lazy_value
is used for a tuple of parameters. This issue could be seen also with @parametrize_with_cases
: idgen
does not seem to be taken into account when cases are unpacked into a tuple. Fixes #144.
Empty case ids are now replaced with '<empty_case_id>'
to avoid ambiguous interpretation of test ids. Fixes #142.
See documentation page for details.
Published by smarie about 4 years ago
clone(self, remove_int_base=False)
API on LazyValue
and LazyTupleItem
instances. With this new API, on old pytest
< 5.3
, other plugins such as pytest-harvest
can easily clone the contents from lazy values without having them inherit from int
- which was a dirty hack used by pytest-cases
to trick pytest
to generate acceptable test ids in these old pytest versions. Also improved the LazyValue
, LazyTuple
and LazyTupleItem
object model with equality and repr. Fixes pytest-harvest#43
See documentation page for details.
Published by smarie about 4 years ago
pytest-pilot
more easily ! Fixes #139
See documentation page for details.
Published by smarie about 4 years ago
See documentation page for details.
Published by smarie about 4 years ago
TypeError: _idval() got an unexpected keyword argument 'item'
with pytest
versions between 3.0.0 and 3.7.4. Fixed #136
See documentation page for details.
Published by smarie about 4 years ago
@parametrize_with_cases
now supports that argnames
is a list or tuple, just as @pytest.mark.parametrize
does. PR #132, by @saroad2
.See documentation page for details.
Published by smarie about 4 years ago
makefun
1.9.3 or above to avoid issue AttributeError: 'functools.partial' object has no attribute '__module__'
mentioned in #128
See documentation page for details.
Published by smarie about 4 years ago
Improved documentation to explain why @fixture
should be used instead of @pytest.fixture
. Fixed #125
Fixed ValueError: fixture is being applied more than once to the same function
when two functions parametrized with the same cases were sitting in the same file. Improved robustness when cases require fixtures, in particular when parametrized test/fixture sits in a class or when several of them sit in a class/module. Fixed #126
See documentation page for details.
Published by smarie about 4 years ago
Added missing deprecation warning on @cases_generator
. Fixes #124.
Removed target
and tags
arguments of @cases_generator
(deprecated api anyway) that were added by mistake in version 2.0.0 but never used.
See documentation page for details.
Published by smarie about 4 years ago
pytest-black
or pytest-flake8
. Fixes #122
See documentation page for details.
Published by smarie about 4 years ago
Fixed issue with @parametrize_with_cases
when two cases with the same id and both requiring a fixture were to be created. Fixed #117.
Fixture closure engine refactoring:
When no fixture unions are present, the fixture closure is now identical to the default one in pytest
, to avoid issues originating from other plugins fiddling with the closure. Fixes #116
New SuperClosure
class representing the "list" facade on top of the fixture tree (instead of FixtureClosureNode
). In addition, this list facade now better handles editing the order of fixtures when possible. Fixes #111.
Session and Module-scoped fixtures that are not used in all union alternatives are not any more torn town/setup across union alternatives. Fixes #120
See documentation page for details.
Published by smarie over 4 years ago
TypeError
with iterable argvalue in standard parametrize. Fixed #115.See documentation page for details.
Published by smarie over 4 years ago
Fixed wrong module string decomposition when passed to cases
argument in @parametrize_with_cases
. Fixes #113
Autouse fixtures are now correctly used. Fixed #114
See documentation page for details.
Published by smarie over 4 years ago
Lazy values (so, test cases) now have a much nicer string representation ; in particular in pytest-harvest
results tables. Fixes #112
See documentation page for details.
Published by smarie over 4 years ago
New documentation page concerning theory of fixture unions. Fixes #109
Using a fixture_ref
in a new-style @parametrize
(with **args
or idgen
) now outputs a correct id. Fixes #110
See documentation page for details.
Published by smarie over 4 years ago
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 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 !
@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-harvest
to collect the timings.
@parametrize_with_cases
can 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 cases
argument to indicate the cases, wherever they come from (no module
argument anymore)
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.
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 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
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
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.
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 @parametrize
or @pytest.mark.parametrize
, just as in pytest ! This includes the ability to put pytest
marks on the whole case, or on some specific parameter values using pytest.param
. @cases_generator
is 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_ref
in the parametrization. Fixes #56.
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.
C/ Misc / pytest goodies
New aliases for readability: @fixture
for @fixture_plus
, and@parametrize
for @parametrize_plus
(both aliases will coexist with the old names). Fixes #107.
@parametrize
was 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.
@parametrize
now raises an explicit error message when the user makes a mistake with the argnames. Fixes #105.
More readable error messages in @parametrize
when lazy_value
does not return the same number of argvalues than expected from the argnames.
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.
Fixed issue with lazy_value
when a single mark is passed in the constructor.
lazy_value
used as a tuple for several arguments now have a correct id generated even in old pytest version 2.
New pytest goodie assert_exception
that can be used as a context manager. Fixes #104.
See documentation page for details.
Published by smarie over 4 years ago
lazy_value
are now resolved at pytest setup
stage, not pytest call
stage. This is important for execution time recorded in the reports (see also pytest-harvest
plugin). Fixes #102
A function used as a lazy_value
can now be marked with pytest marks. Fixes #99
A lazy_value
now has a nicer id when it is a partial. Fixes #97
Removed annoying PytestUnknownMarkWarning
warning message when a mark was used on a case. Fixes #100
See documentation page for details.
Published by smarie over 4 years ago
lazy_value
for parametrize_plus
. Fixes #92
See documentation page for details.