You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As discussed in #158 (in particular #158 (comment) and #158 (comment)), when a fixture is created for a parametrized case, if that case is used in a test that lies in a separate module, the fixture won't be visible and test collection will fail.
Trying to run test_foo will result in an error during collection:
_______________________ ERROR at setup of test_foo[foo] _______________________
file .../test_foo.py, line 5: source code not available
file <makefun-gen-14>, line 1: source code not available
file ...
E fixture 'case_foo_y' not found
> available fixtures: cache, capfd, capfdbinary, caplog, capsys, capsysbinary, doctest_namespace, foo, monkeypatch, pytestconfig, record_property, record_testsuite_property, record_xml_attribute, recwarn, test_foo_y, tmp_path, tmp_path_factory, tmpdir, tmpdir_factory
> use 'pytest --fixtures [testpath]' for help on them.
Workarounds
Possible workarounds are:
Import everything from the cases module to ensure all dynamically generated fixtures are visible in the test module too: from test_foo_cases import *
Selectively import the dynamically generated fixture in the test module: case_foo_y = test_foo_cases.case_foo_y. This relies on knowing the name of the generated fixture.
Possible solutions
Dynamically add the fixture to all modules that reference the case too?
Instead of adding the fixture to the cases module, add it to the closest conftest.py available?
The text was updated successfully, but these errors were encountered:
Nice workaround from test_foo_cases import * ! I did not think it would work but actually there is no reason it shouldnt
Another possible solution is : stop creating hidden fixtures in @parametrize (#170). A bit ambitious/challenging but not impossible.
plammens
changed the title
Fixture creation for parametrized case not visible to test function in different module
Fixture created for parametrized case not visible to test function in different module
Dec 18, 2020
As discussed in #158 (in particular #158 (comment) and #158 (comment)), when a fixture is created for a parametrized case, if that case is used in a test that lies in a separate module, the fixture won't be visible and test collection will fail.
Related to #170, #169
Example
In the file
test_foo_cases.py
:In
test_foo.py
:Trying to run
test_foo
will result in an error during collection:Workarounds
Possible workarounds are:
from test_foo_cases import *
case_foo_y = test_foo_cases.case_foo_y
. This relies on knowing the name of the generated fixture.Possible solutions
conftest.py
available?The text was updated successfully, but these errors were encountered: