Fixtures in multiple conftest files run in nested order #8475
Replies: 1 comment
|
If You do not need to duplicate the fixture implementation. Put the implementation in a shared plugin/module, and import/re-export it from each package's That gives pytest an unambiguous package fixture boundary for each sibling. The posted result was also produced with pytest 6.2.2; collection/package handling has changed substantially since then. I would upgrade before building a workaround around that old nested teardown behavior. Please mark this answer as accepted if it helped, thank you. |
Uh oh!
There was an error while loading. Please reload this page.
I have the following project structure
I have a fixture I want to run for every Tests_ folder (
TestsAandTestsB), so I created a fixture with scope packageWhen added in
conftest.pyunder Tests it runs only ones although I added__init__.pyfile toTestsAandTestsBto make them a package.When I added a
conftest.pywith the fixture to each of the Tests_ folders both executed the setup code before the tests under it, but executed the teardown code only after all the tests finished, and as if they were executed as nested:Which causes some issues, especially since I have more than two Tests_ folders.
Why does it behave like this, and more important how can I solve it without flattening the test hierarchy or adding
conftest.pyto every SubFolder.I'm using Python 3.8 and Pytest 6.2.2 if it makes any difference.
All reactions