-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Nested conftest.py #1931
Comments
Do you have an example project somewhere? Using fixtures from a root |
Well, indeed it is working correctly. I think there was some misunderstanding with my colleagues of what they're trying to achieve. Sorry about that and thanks for your time! |
Just a thought ... I too face the same issue Here is how i handled it Session related fixtures are kept in root directory all sub conftest imports from root conftest and this way sub conftest has their and parents conftest features and this helps in maintaining a readable and clean code. |
When setting up the fixture list within a class, we were doing something along the lines of: ``` class TestClass: UNIT = {"cluster": [local_cluster]} ``` This requires an import of `local_cluster` from conftest. Turns out, this causes session scoped fixtures to be recomputed (pytest-dev/pytest#3217). It's bad practice to import from conftest in the first place. So, I changed the fixtures that run `getfixturevalue` to just use the string argument, and we can avoid importing, and rely on pytest to set up the fixtures correctly. Now we set up fixtures like so: ``` class TestClass: UNIT = {"cluster": ["local_cluster"]} ``` Moreover... if a fixture is defined in a nested `conftest.py`, and imported in the global `conftest.py`, then there can be conflicts. The way tests work is that they'll look heirarchically upward in conftest.py files, and then grab the first fixture they find that matches the name. Even if the global `conftest.py` imports from a nested `conftest.py` file, it is considered a different fixture object (unintuitive, yes). This will sometimes lead to session scoped fixtures being initialized twice in the same session. More info on nested conftest.py files [here](pytest-dev/pytest#1931).
Hi guys,
We have integrated pytest and actually we're using it for a couple of month. You're done the great work, so far it is the best testing framework for Python I've ever seen.
However, now we moved our tests in different folders and we'd like to have some hierarchy in our fixtures and conftest.py files.
Let's say, we have nested test directory structure and I want to have like general fixtures in parent conftest.py and component-like fixtures in the nested conftest.py.
So fat pytest seems to use only the deepest one. Is it possible to make one test use fixtures from different conftest.py files?
Thanks,
Constantine
The text was updated successfully, but these errors were encountered: