-
-
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
Consider plugins loaded by PYTEST_PLUGINS for assertion rewrite #2186
Consider plugins loaded by PYTEST_PLUGINS for assertion rewrite #2186
Conversation
self._import_plugin_specs(os.environ.get("PYTEST_PLUGINS")) | ||
specs = os.environ.get("PYTEST_PLUGINS") | ||
if specs: | ||
plugins = specs.split(',') |
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.
this it is a behaviour change at fist glance
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.
the real marking should be in the _import_plugin_specs
function before the import loop but after the split
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.
It feels to me import_plugin
is the better place for it because all other functions which import a plugin eventually call it, so don't miss marking plugins for assertion rewrite:
consider_pluginarg -> import_plugin
consider_conftest -> consider_module -> _import_plugin_specs -> import_plugin
consider_module -> _import_plugin_specs -> import_plugin
So I think this actually also fixes consider_pluginarg
.
Could you provide an example were this would be a behavior change?
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.
thanks for taking a deeper look, the location you mention is indeed a better place
my feat of the behaviour change has 2 parts 1. we now pass more different types trough the functions (before it was None or a string, now it is None, a string or a list)
upon investigation of course i noticed that the _import_plugin_specs
does filter "false" values
we may experience misbehavior on the value "," however (which would also hold prior to the change)
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.
Thanks for the reply @RonnyPfannschmidt
- we now pass more different types trough the functions (before it was None or a string, now it is None, a string or a list)
You mean the change in consider_env
? I don't see a behavior change there, because it went from passing None
or str
to passing a list[str]
to _import_plugin_specs
, which was always supported by _import_plugin_specs
anyway. Or do you mean that previously consider_env
would always call _import_plugin_specs
, even with None
? I guess we can change consider_env
so that it calls _import_plugin_specs
even when PYTEST_PLUGINS
is not defined, but it seems to me an stretch to consider this a "behavior change" (which I'm assuming you mean to put this fix into features
instead of master
). If that's what you mean, could you provide an example of a situation where this would affect users at all, considering that the config
module is rarely (if ever) overwritten by plugins and users?
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.
Also, I think that all those places with handle the different ways to specify a plugin are getting unhandy to maintain.
if specs:
specs = specs.split(',')
And:
if isinstance(plugins, str):
plugins = [plugins]
Should we add a
def _get_plugins_as_list(specs: Union[str, None, List[str])) -> List[str]
Function and use it everywhere? Some subtle bugs have crept in because this logic is implemented everywhere, sometimes incompletely.
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.
that may be necessary, and a good thing to do, we have so many inconsistencies ^^
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.
OK, thanks, will do it then.
And about your reservations for this being a behavior change?
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.
with the right location for the marking code i no longer have any reservations at all, thanks
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.
Great. 👍
Implemented the change as we agreed,
self._import_plugin_specs(os.environ.get("PYTEST_PLUGINS")) | ||
specs = os.environ.get("PYTEST_PLUGINS") | ||
if specs: | ||
plugins = specs.split(',') |
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.
the real marking should be in the _import_plugin_specs
function before the import loop but after the split
0bc8310
to
7cd7c28
Compare
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.
lovely finalization, ready to merge i presume?
Thanks Ronny! Merging then. 😁 |
Fix #2185