Reputation: 839
I have the following directory structure:
root --- conftest.py
|
|
----- dev
|
|
---- conftest.py
|
---- other python files
If I run py.test in the dev directory, the conftest.py in the root directory gets called. I have not been able to figure out why. I have not set the PYTHONPATH environmental variable.
Upvotes: 2
Views: 6953
Reputation: 2131
From https://docs.pytest.org/en/latest/how-to/writing_plugins.html#plugin-discovery-order-at-tool-startup:
by loading all conftest.py files as inferred by the command line invocation:
- if no test paths are specified use current dir as a test path
- if exists, load conftest.py and test*/conftest.py relative to the directory part of the first test path.
Note that pytest does not find conftest.py files in deeper nested sub directories at tool startup. It is usually a good idea to keep your conftest.py file in the top level test or project root directory.
Looks like it is documented behavior to load conftest.py from the root directory, if you don't specify a test path to me.
Upvotes: 1