-
-
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
Load plugins referencing entry point name provided via config and env var #12616
base: main
Are you sure you want to change the base?
Load plugins referencing entry point name provided via config and env var #12616
Conversation
1b229ed
to
ba3b710
Compare
@@ -828,7 +828,7 @@ def _import_plugin_specs( | |||
) -> None: | |||
plugins = _get_plugin_specs_as_list(spec) | |||
for import_spec in plugins: | |||
self.import_plugin(import_spec) | |||
self.import_plugin(import_spec, consider_entry_points=True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add tests to prove that it works and demonstrate the difference with the previous behavior.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can probably start with some merge of test_missing_required_plugins
(it looks like the pytest11
entry point is created there) and test_early_config_cmdline
(some kind of PYTEST_PLUGINS
handling). But then some questions arises, for example: why is there the pytester.syspathinsert()
call? After reading the doc it looks like the call is just a no-op, but this conclusion is apparently wrong.
I'm very sorry, but I'll need to leave this for somebody else who actually knows Python. Disclaimer: I'm not a Python developer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd imagine that it sets $PYTHONPATH
just for the subprocess invocation of pytest, which is what makes it possible for that subprocess to import <tested_pytest_plugin>
residing on that path.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wouldn't merge tests at this point. Maybe, in a separate refactoring. But it's always easier to add a separate one and not care if you break other ones accidentally. Especially, if you're unsure.
As for the tips, using monkeypatch.setenv()
should be a way to test the env var bit. It might be a bit more involved with generating a custom config, though. Still, I think it's a good starting point.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, this is really out of my knowledge.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, so don't mark it as resolved because hiding the discussion from people doesn't mean that it shouldn't be solved before merging.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like the right place to put the tests in would be test_pluginmanager.py::TestPytestPluginManager
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's also test_early_load_setuptools_name
@ acceptance_test.py
Could you also add description to the PR and the commit, perhaps? |
Sounds reasonable to me. Normally this doesn't matter because entrypoint plugins are loaded already by the time The |
ba3b710
to
cb61cef
Compare
Done. |
What kind of description would you like to see? |
cb61cef
to
69121d1
Compare
3a63cdb
to
387ce53
Compare
Most of the information from the issue. Things that will end up in the merged commit. You only added a link and a word “fixes” but any other information is only available though Git paleontology. In general, people checking out that commit shouldn't have to go to external places to understand what it does. It should be summarized clearly in the message itself. A good guide to follow could be https://cbea.ms/git-commit/, for example. |
82619a9
to
83ccca0
Compare
Changed. Is it better? |
83ccca0
to
b939426
Compare
b939426
to
606b2cd
Compare
Yes. Much better. This also reveals that we forgot to mention the effect of such plugins being listed in the console output in the changelog fragment. I think it'd be useful for the users to know that this changed. |
This also reminds me that this PR does not fully fix #12615 because plugins loaded the old way are still not listed in the list. :-( |
9bb5997
to
5b20734
Compare
Wait a second... I'm confused. How are these two issues separate? |
They are separate because this PR does not fix #12615 at all. With this PR and without this PR the What will differ is the
with this PR merged we will get this:
|
@mtelka okay, thank you! Now I understand the scope of the PR better. May I suggest changing the title of the PR/commit to something along the lines of “Load plugins referencing entry point name provided via config and env var”. I think, this would better reflect what the effect of applying your patch is. |
I do not mind. Will do the change in a minute... |
5b20734
to
55c8117
Compare
... but, honestly, the new one is more confusing and less clear to me. But as I said, I do not mind. |
@webknjaz, should I squash (I prefer to)? Not sure what are rules for this project... |
Could you also drop the mention of “ |
@mtelka feel free to squash. If the commits are nicely crafted, the natural merge is typically used most of the time. If they are a mess, the maintainers may choose to use the squash strategy. |
699855b
to
106c135
Compare
… var This allows to load plugins via `PYTEST_PLUGINS` environment variable and `pytest_plugins` global variable using their names in installed package entry points. Closes pytest-dev#12624.
106c135
to
f00d15e
Compare
I found that when I run tests with this change in place and with the following modification to
then the following 16 tests fails because they are unable to find
The fix seems obvious and we do need to remove the |
This allows to load plugins via
PYTEST_PLUGINS
environment variable andpytest_plugins
global variable using their names in installed package entry points.Closes #12624.