What determines conftest hook order? #11226
Unanswered
scott-codecov
asked this question in
Q&A
Replies: 1 comment
-
Hi @scott-codecov, in fact there is a little mechanism to control the ordering by using import pytest
@pytest.hookimpl(tryfirst=True)
def pytest_configure():
print("OUTER") and import pytest
@pytest.hookimpl(trylast=True)
def pytest_configure():
print("INNER") Then your order is always the same: first OUTER then INNER. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I noticed that the order of
conftest.py
hooks changes depending on whether or not test files are passed as CLI arguments topytest
.For example, considering the following directory structure:
Running
python -m pytest
runs the outer conftest hooks first followed by the nested conftest hooks.But if I specify the test files with
python -m pytest tests/test_outer.py tests/nested/test_nested.py
then I see that the inner conftest runs before the outer conftest.Here's a more complete demonstration of this: https://github.com/scott-codecov/pytest-order-demo
Is there a way to control this ordering such that it's deterministic regardless of whether
pytest
is collecting the test files vs. specifying them explicitly?Beta Was this translation helpful? Give feedback.
All reactions