-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
fixture hooks not running in packages #2361
Comments
At first glance your example should be running |
Btw. thanks a lot for the detailed report and the sample repository to boot! We really appreciate throughout reports like this one! 👍 |
I bumped into the same issue and did some investigation.
This explains @Isenta's observation regarding error being raised for incorrect parameters: an error is raised when the first |
Okay, looks like this is because So this looks like a bug with either Conclusion. The issue happens only with Same issue with |
thanks for the investigation, that gave me an idea where to look while tracing it pytest fixtures consider fixture hooks based on the fspath of the requesting node (and gets fs hook proxies for the contests along the way for a session scoped fixture, the requesting node is the as such contests along the way can no longer be considered as far a i can tell this is per design and for good reasons, just very confusing without more context |
@RonnyPfannschmidt, thanks for an explanation. Looks like this is indeed not a bug... Although it's inconvenient in some cases. Consider I have a project with all tests stuff being put in a separate
With this behaviour, I will have to pollute project's root directory with a separate |
@MarSoft for now i am not aware of a known workaround, we'd have to come up with one |
Just for record: the semi-workaround I use for now is to have the hook code declared in my "main"
But for non-session-scoped fixtures it would probably result in this hook being called twice (once from root conftest and once from main conftest). |
I stumbled upon the same issue. I have |
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
andb
for example, then the value ofb
would depend on the value ofa
.I intend to use the
pytest_fixture_setup
hook, somehow, but:pytest_fixture_setup
intests/mypackage/conftest.py
, it is never run.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:
the conftest is the same, so I expect to see
fixture_setup.package
at some point.The text was updated successfully, but these errors were encountered: