Open astraw38 opened 7 years ago
a few notes
at the pytest-sprint in june we did conceptualize many aspects of fixture reuse, name-spacing but didn't find time to implement/experiment
we should start to document the finer details and some proposal (that takes a lot of time that many from us don't don't have readily and consistently)
Ah, I remember now why we didn't do the pytest_plugins = ...
in the past -- it makes it active globally, rather than at the current conftest level & below. That's a problem for hooks & autouse fixtures. I should add that downside to the original post, since that's a critical difference to importing.
Using fixtures from plugins is problematic because, as was already mentioned, once a plugin is loaded, the changes it makes are available globally. This is not explained clearly in the documentation which only warns about the usage of plugins in non-root conftest.py
files. And the current versions of pytest
explicitly disallow that. But a similar effect can be observed when a plugin is imported in any test module.
It changes the behavior globally. Not only in the module from where it was imported. Not even only in the directory subtree from where it was imported. And that is, in my opinion, very confusing.
Since plugins affect the behavior globally, perhaps they should only be allowed in the top-level conftest.py
file.
It'd be very helpful to have one canonical way to re-use fixture code between test modules. Right now, I know of 3 ways to do this, each with their own downsides:
pytest_plugins = 'path.to.conftest'
-- Will result in pytest errors if you run the current module and the module the conftest came from at the same time. Also makes the plugin globally active, which isn't always desired.