-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Have a way to control order of plugin loading #935
Comments
needs consideration in pluggy i think we might want to add a own setuptools metadata writer to pluggy, to have more informative plugin specs |
We could just sort the entrypoints before calling them, no? Would there by any problem if I decide to rename my entrypoint? |
in my oppinion odering by name or lexical order is flawed when dependencies come into play |
Just for reference, my original issue was with the imports, I wanted pytest-cov to be imported before pytest-benchmark. I have found a workaround since (albeit a bit contrived), just to measure coverage ... |
early plugin import is planned since a while, just never found a god way to implement |
I can see how this would be useful for pytest-cov, but it shouldn't block 3.0. Changing the milestone to 3.1 for now. |
I'm also a victim of this, I'm using pytest_env and pytest_django, my django settings read some variables from environment (that I want to set with pytest_env), but in some computers pytest_django loads before pytest_env, so tests run without the environment. |
Back to the topic: the idea is to just somehow "mark" a plugin so it tries to be loaded as early as possible? How one would mark such a plugin? |
I think the easiest way is making py.test load first the plugins passed with the -p command line option before the automatic loading using pkg_resources |
@dedsm thanks for the suggestion. I think it is a valid idea, but that does not cover (heh) pytest-cov though... it is a plugin which by definition should be loaded as early as possible, independently if users have passed it into the command line or not. I'm wondering if people have something in mind already. |
One idea is to introduce another alternative entrypoint name that supports ordering. The object (a module?) that a plugin exports though that entrypoint should have some sort of |
Actually scratch that, accessing the priority attribute would imply importing module and causing undue issues. Perhaps an entrypoint just for the priority number? Hmmmm |
Would we need to have priority numbers, or something like Not that I have a better idea, mind you. 😜 |
The first thing which came to mind are As for that vs. a priority value, I've actually talked to Holger about that one for plugin hooks, and we agreed it's the much nicer (if less powerful) mechanism, because it requires no (hard to impossible) coordination between authors. As a counter-example, nose seems to use priority values, and apparently that didn't end up being a good idea 😉 |
I like the tryfirst trylast idea, I think that would solve most of the cases. for the more obscure ones, how about having a way to alter the order via the config file? a simple list that the developer can alter with a placeholder for the "rest"? something like [pytest] that coupled with debug information about the order of loading would be enough for the rest of the cases. |
i propose the concept of a pluginspec instead of having just random modules without order, each plugin should have a spec object telling its dependencies, and the order for consideration for required/optional dependencies tryfirst/last is imho pretty much a horrific mess |
the problem is none of these cases are because of lack of dependencies, the django plugin should never depend on the env plugin, same as in the case of the coverage plugin |
so what will you do if both plugins become tryfirst? tryfirst/last do not at all solve the problem, they just bolt a non-solution on top what would help is a way to specifiy dependencies in plugins and out of them also we need a topology anyway - for example py.tests internal plugins can never be loaded via setuptools, and tryfirst/last couldnt fix that |
that's why I agree on having a really simple ordering builtin, but ultimately the control should reside in the developer because as far as I can see this problem is not common and should be treated individually |
for me the problem is very common and currently solved by not using setuptools, but relying purely on ordered pytest-plugins specification |
I agree on setuptools not being a solution, but how and who should decide the topology of plugins that don't have anything to do with each other? it's naiveness thinking that every plugin will specify that relationship with all the rest of the plugins, it's not maintainable |
there is need for 2 mechanisms a) plugin authors spelling dependencies they do know |
So how would |
i propose a priority value for an "absolute order" and before/after listing for putting topology on top of that also a pytest.ini entry for adding extra topology "hints" |
Related (and perhaps I should report an actual bug on this one): If I look at the help with
Using that and a suggestion above, hoping I could early-load the coverage plugin, I tried that out:
Using |
The plugin setuptools name and the import name for the plugin differ, one can block by setuptools name but cant early load by it |
That's incredible confusing, and also not documented. Also, if that's the case, I can't figure out what I'm supposed to use to make
Is |
its simply not in sync with the setuptools plugin loading mechanism which registers plugins at a different name than their import name while -p works in terms of import names so in a sense - |
Want me to file a new bug about it? |
Ok so I've tried patching Well, nothing short of doing it at import time which is way too tricky (inspecting the call stack? ugh ...). |
… plugins. For now this change doesn't really solve anything, see: pytest-dev/pytest#935 (comment)
Now that [pytest]
addopts = -p pytest_cov Of course, it would still be nice to have a way for plugins to handle this themselves somehow. |
Hi @nicoddemus I tried that but it does not solve the issue. The command launched by travis is "pytest --cov", the configuration loaded is the exact one you advise. The "pytest11" entrypoint is the root of the module leading to no coverage at all. What's confusing here is that between your comment and the documentation, the content of the file is not the same. Also this page is a bit unclear, what specific action is suppose to start pytest-cov engine manually? Do you have any explanation, documentation, tips to share as to what are the exact options to use in order to make sure that pytest-cov can be use to check coverage of a pytest plugin (containing a "pytest11" entrypoint) ? Thanks again |
I've solved this by using coverage natively instead through pytest-cov, see https://github.com/pytest-dev/pytest-print/blob/eb776107d83a94e90edeb7381d679251ae45bcf0/tox.ini#L27-L33 👍 |
Moving from conftest.py to pytest_plugin.py (which comes via a setuptools entry point) requires a workaround to prevent loss of coverage from real libtmux tests relying on our pytest plugin. See also: - https://pytest-cov.readthedocs.io/en/latest/plugins.html - pytest-dev/pytest#935 (comment)
Moving from conftest.py to pytest_plugin.py (which comes via a setuptools entry point) requires a workaround to prevent loss of coverage from real libtmux tests relying on our pytest plugin. See also: - https://pytest-cov.readthedocs.io/en/latest/plugins.html - pytest-dev/pytest#935 (comment)
Moving from conftest.py to pytest_plugin.py (which comes via a setuptools entry point) requires a workaround to prevent loss of coverage from real libtmux tests relying on our pytest plugin. See also: - https://pytest-cov.readthedocs.io/en/latest/plugins.html - pytest-dev/pytest#935 (comment)
2023 and still no way to do so? i'm trying to write plugin to a pytest-plugin. and the only way to do so is to make sure that my plugin is loaded before the other plugin |
So far nobody came up with a good solution in the upstream project pluggy It's been on my radar before I had kids, now not so much |
…entally The order in which pytest plugins are loaded is currently nondeterministic, see pytest-dev/pytest#935. So we have no chance to override a fixture from another plugin in our plugin, this must instead be done in the project's conftest.py (which is guaranteed to have precedence over plugins).
…entally The order in which pytest plugins are loaded is currently nondeterministic, see pytest-dev/pytest#935. So we have no chance to override a fixture from another plugin in our plugin, this must instead be done in the project's conftest.py (which is guaranteed to have precedence over plugins).
It appears that the order of
pkg_resources.iter_entry_points
is pretty arbitrary.I would like pytest to order that so I can say pytest-cov must load before pytest-benchmark. Currently I cannot use pytest-cov to measure pytest-benchmark due to the ordering issue.
The text was updated successfully, but these errors were encountered: