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
Currently it seems that fixtures must be defined in test_foo.py, and defining a fixture in test_foo_cases.py does not work. It would be nice if fixtures defined in test_foo_cases.py could be used within the same file.
Motivation
If the test cases defined in test_foo_cases.py will use a fixture, being able to those fixtures in the same file would be good for organization (data locality).
$ pytest
================================================================== test session starts ==================================================================
platform linux -- Python 3.9.6, pytest-6.2.4, py-1.10.0, pluggy-0.13.1
rootdir: /home/jbss/pysc/tensor_from_dom2
plugins: cov-2.12.1, hydra-core-1.1.1, cases-3.6.3
collected 1 item
test_foo.py E [100%]
======================================================================== ERRORS =========================================================================
_________________________________________________________ ERROR at setup of test_simple[simple] _________________________________________________________
file /home/jbss/pysc/tensor_from_dom2/test_foo.py, line 3: source code not available
file <makefun-gen-8>, line 1: source code not available
file <makefun-gen-6>, line 1: source code not available
E fixture 'fixt' not found
> available fixtures: cache, capfd, capfdbinary, caplog, capsys, capsysbinary, cov, current_cases, doctest_namespace, hydra_restore_singletons, hydra_sweep_runner, hydra_task_runner, monkeypatch, no_cover, pytestconfig, record_property, record_testsuite_property, record_xml_attribute, recwarn, simple, symbol_id, test_simple_test_case, tick_size, tmp_path, tmp_path_factory, tmpdir, tmpdir_factory
> use 'pytest --fixtures [testpath]' for help on them.
<makefun-gen-6>:1
================================================================ short test summary info ================================================================
ERROR test_foo.py::test_simple[simple]
=================================================================== 1 error in 0.02s ====================================================================
Workaround
The fixture can be defined in test_foo.py or in conftest.py:
$ pytest
...
=================================================================== 1 passed in 0.02s ===================================================================
This is documented in the Cases Requiring Fixtures section of the docs: "make sure the fixture exists or is imported either in the module where @parametrize_with_cases is used, or in a conftest.py file in one of the parent packages."
I think that the workaround for issue #174 should solve your issue as well, did you try ?
# test_foo.pyfrompytest_casesimportparametrize_with_casesfrom .test_foo_casesimport*# <-- this line does the trick@parametrize_with_cases("test_case")deftest_simple(test_case):
asserttest_case==124
Currently it seems that fixtures must be defined in
test_foo.py
, and defining a fixture intest_foo_cases.py
does not work. It would be nice if fixtures defined intest_foo_cases.py
could be used within the same file.Motivation
If the test cases defined in
test_foo_cases.py
will use a fixture, being able to those fixtures in the same file would be good for organization (data locality).Repro:
Currently the following does not work:
This fails as follows:
Workaround
The fixture can be defined in
test_foo.py
or inconftest.py
:This is documented in the Cases Requiring Fixtures section of the docs: "make sure the fixture exists or is imported either in the module where @parametrize_with_cases is used, or in a conftest.py file in one of the parent packages."
Possibly related to this issue: #174
The text was updated successfully, but these errors were encountered: