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

conftest.py loaded in wrong order. #1404

Closed
AndreiPashkin opened this issue Feb 20, 2016 · 2 comments
Closed

conftest.py loaded in wrong order. #1404

AndreiPashkin opened this issue Feb 20, 2016 · 2 comments
Labels
topic: collection related to the collection phase topic: config related to config handling, argument parsing and config file

Comments

@AndreiPashkin
Copy link

Description of the bug:

Docs says:

Hook Session and test running activities will invoke all hooks defined
in conftest.py files closer to the root of the filesystem.

But my tests shows, that this is happens in some other way. Here is my directory structure.

.
├── a
│   ├── b
│   │   ├── conftest.py
│   │   └── test_b.py
│   ├── conftest.py
│   └── test_a.py
├── c
│   ├── conftest.py
│   └── test_c.py
├── conftest.py
└── test_root.py

Each conftest.py file has such content:

def pytest_runtest_setup(item):
    # called for running each test in 'a' directory
    print ("setting up <name directory>", item)

Here is what I get, executing py.test -svvv .:

test_root.py::test_root ('setting up b', <Function 'test_root'>)
('setting up root', <Function 'test_root'>)
PASSED
a/test_a.py::test_a ('setting up a', <Function 'test_a'>)
('setting up root', <Function 'test_a'>)
PASSED
a/b/test_b.py::test_b ('setting up b', <Function 'test_b'>)
('setting up a', <Function 'test_b'>)
('setting up root', <Function 'test_b'>)
PASSED
c/test_c.py::test_c ('setting up c', <Function 'test_c'>)
('setting up root', <Function 'test_c'>)
PASSED

Notice the first entry - for test_root.py loaded conftest.py files from root directoriy and b. But b is not closer to the filesystem root. Also it is not clear for me, why in some cases two conftest.py are loaded and in some - three?

Output of pip list:

pip (8.0.2)
py (1.4.31)
pytest (2.8.7)
setuptools (18.2)

Versions:

OS: Linux Mint 17.3 Rosa
PyTest: 2.8.7

Example project:

https://github.com/AndrewPashkin/pytest_issue_1404

@elinxie
Copy link

elinxie commented Mar 24, 2023

Is there any resolution on this topic?

@nicoddemus
Copy link
Member

Hi @elinxie,

Seems like this issue has been fixed, as I obtain the expected results in 7.2.2:

λ pytest .tmp\1404 -sv --no-header
======================== test session starts ========================
collected 4 items

.tmp\1404\test_root.py::test_root setting up root <Function test_root>
PASSED
.tmp\1404\a\test_a.py::test_a setting up a <Function test_a>
setting up root <Function test_a>
PASSED
.tmp\1404\a\b\test_b.py::test_b setting up b <Function test_b>
setting up a <Function test_b>
setting up root <Function test_b>
PASSED
.tmp\1404\c\test_c.py::test_c setting up c <Function test_c>
setting up root <Function test_c>
PASSED

========================= 4 passed in 0.02s =========================

So, for each test file, the hooks in each conftest.py file are called from the directory of the test file, upwards in the file system.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: collection related to the collection phase topic: config related to config handling, argument parsing and config file
Projects
None yet
Development

No branches or pull requests

4 participants