-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
[WIP] load_entrypoint_plugins option/marker #4521
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
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
bff3878
Add load_entrypoint_plugins ini option/marker
blueyed 0407d86
remove marker: option should be enough, and marker should be with pyt…
blueyed 5c672c5
type=args
blueyed 8b0bdab
Handle AttributeError in _getini
blueyed ebd606a
doc
blueyed File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -154,15 +154,17 @@ def directory_arg(path, optname): | |
| def get_config(args=None): | ||
| # subsequent calls to main will create a fresh instance | ||
| pluginmanager = PytestPluginManager() | ||
| config = Config(pluginmanager) | ||
| # XXX: storing it on the instance is required to make it available in | ||
| # is_blocked, which is the callback used with load_entrypoint_plugins. | ||
| pluginmanager.config = Config(pluginmanager) | ||
|
|
||
| if args is not None: | ||
| # Handle any "-p no:plugin" args. | ||
| pluginmanager.consider_preparse(args) | ||
|
|
||
| for spec in default_plugins: | ||
| pluginmanager.import_plugin(spec) | ||
| return config | ||
| return pluginmanager.config | ||
|
|
||
|
|
||
| def get_plugin_manager(): | ||
|
|
@@ -246,6 +248,20 @@ def __init__(self): | |
| # Used to know when we are importing conftests after the pytest_configure stage | ||
| self._configured = False | ||
|
|
||
| def is_blocked(self, name): | ||
| ret = super(PytestPluginManager, self).is_blocked(name) | ||
| if not ret: | ||
| try: | ||
| config = self.config | ||
| except AttributeError: | ||
| pass | ||
| else: | ||
| load_entrypoint_plugins = config.getini("load_entrypoint_plugins") | ||
| if load_entrypoint_plugins is not notset: | ||
| if name not in load_entrypoint_plugins: | ||
| return True | ||
| return ret | ||
|
|
||
| def addhooks(self, module_or_class): | ||
| """ | ||
| .. deprecated:: 2.8 | ||
|
|
@@ -334,6 +350,14 @@ def hasplugin(self, name): | |
| """Return True if the plugin with the given name is registered.""" | ||
| return bool(self.get_plugin(name)) | ||
|
|
||
| def pytest_addoption(self, parser): | ||
| parser.addini( | ||
| "load_entrypoint_plugins", | ||
| help="only load specified plugins via entrypoint", | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use |
||
| default=notset, | ||
| type="args", | ||
| ) | ||
|
|
||
| def pytest_configure(self, config): | ||
| # XXX now that the pluginmanager exposes hookimpl(tryfirst...) | ||
| # we should remove tryfirst/trylast as markers | ||
|
|
@@ -792,6 +816,10 @@ def _mark_plugins_for_rewrite(self, hook): | |
|
|
||
| self.pluginmanager.rewrite_hook = hook | ||
|
|
||
| load_entrypoint_plugins = self.getini("load_entrypoint_plugins") | ||
| if load_entrypoint_plugins is not notset and not len(load_entrypoint_plugins): | ||
| return | ||
|
|
||
| if os.environ.get("PYTEST_DISABLE_PLUGIN_AUTOLOAD"): | ||
| # We don't autoload from setuptools entry points, no need to continue. | ||
| return | ||
|
|
@@ -810,7 +838,8 @@ def _mark_plugins_for_rewrite(self, hook): | |
| ) | ||
|
|
||
| for name in _iter_rewritable_modules(package_files): | ||
| hook.mark_rewrite(name) | ||
| if load_entrypoint_plugins is notset or name in load_entrypoint_plugins: | ||
| hook.mark_rewrite(name) | ||
|
|
||
| def _validate_args(self, args, via): | ||
| """Validate known args.""" | ||
|
|
@@ -944,7 +973,7 @@ def _getini(self, name): | |
| if value is None: | ||
| try: | ||
| value = self.inicfg[name] | ||
| except KeyError: | ||
| except (AttributeError, KeyError): | ||
| if default is not None: | ||
| return default | ||
| if type is None: | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 will be a bummer to write one, but I guess we should add a functional test for this?
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.
Yeah, tests are fine.. :D