Skip to content
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

highest conftest.py in my directory tree is not being loaded #11261

Closed
blockjon-dd opened this issue Jul 30, 2023 · 3 comments
Closed

highest conftest.py in my directory tree is not being loaded #11261

blockjon-dd opened this issue Jul 30, 2023 · 3 comments

Comments

@blockjon-dd
Copy link

I created a fixture located in my test/ directory in conftest.py.

I also have another conftest.py file located under test/unit with more fixtures specific to unit tests.

I am observing that after I upgrade from pytest 7.3.1 to 7.4.0, the "higher" of the two conftest.py files I have is never loaded.

Downgrading back to pytest 7.3.1 restores the expected functionality.

<snip>
...
pytest-cov==4.1.0
pytest-freezer==0.4.8
pytest-mock==3.11.1
pytest-xdist==3.3.1
pytest==7.3.1
...
</snip>
@RonnyPfannschmidt
Copy link
Member

Do you have a minimum reproducing example that includes configuration/invocation option?

@ployt0
Copy link

ployt0 commented Jul 31, 2023

Normal path:

pip install pytest
cd pytest11261/test/unit 
pytest

Happy path:

pip install pytest==7.3.1
cd pytest11261/test/unit 
pytest

pytest11261.zip

@The-Compiler
Copy link
Member

This is due to this change from the changelog:

#11043: When --confcutdir is not specified, and there is no config file present, the conftest cutoff directory (--confcutdir) is now set to the rootdir. Previously in such cases, conftest.py files would be probed all the way to the root directory of the filesystem. If you are badly affected by this change, consider adding an empty config file to your desired cutoff directory, or explicitly set --confcutdir.

Since there is no config file in your project directory (pytest.ini, pyproject.toml, tox.ini, or setup.cfg), pytest determines rootdir: .../pytest11261/test/unit and doesn't load the conftest.py outside of it.

As mentioned by the changelog, creating e.g. an empty pytest.ini in the pytest11261 folder fixes this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants