-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Description
Hi there, thanks for maintaining such a great tool.
(pytest 3.0.7)
I have an unexplained behavior with conftest and fixtures,
I try to write a fixture that would depend on other fixtures optionally. If a test uses both the fixtures a and b for example, then the value of b would depend on the value of a.
I intend to use the pytest_fixture_setup hook, somehow, but:
- When I define
pytest_fixture_setupintests/mypackage/conftest.py, it is never run. - When I define it in
conftest.py(root, not in package), it is run.
This contradicts what I understood from:
https://docs.pytest.org/en/latest/writing_plugins.html#conftest-py-local-per-directory-plugins
(use conftest in the package where you need it, avoid non-package ones because imports are source of errors).
Even weirder, if you make an error on the hook parameters in tests/mypackage/conftest.py, pytest will raise an error. Fix the typo, the hook is ignored.
I pushed an empty project showing this issue:
https://github.com/lsenta/pytest-conftest-broken
Here's the output:
laurent at HALIX in ~/dev/pytest-conftest-broken on master
› tree
.
├── conftest.py
└── some_test
├── __init__.py
├── conftest.py
└── test_x.py
laurent at HALIX in ~/dev/pytest-conftest-broken on master
› pytest -s
============================ test session starts =============================
platform darwin -- Python 3.6.0, pytest-3.0.6, py-1.4.32, pluggy-0.4.0
rootdir: /Users/laurent/dev/pytest-conftest-broken, inifile:
plugins: timeout-1.2.0
collected 2 items
some_test/test_x.py runtest_setup.package
runtest_setup.project
fixture_setup.project
.runtest_setup.package
runtest_setup.project
fixture_setup.project
.
========================== 2 passed in 0.01 seconds ==========================
the conftest is the same, so I expect to see fixture_setup.package at some point.