-
-
Notifications
You must be signed in to change notification settings - Fork 3k
add --disable-plugin-autoload #13253
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
Merged
+151
−31
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
6a7958c
add --disable-plugin-autoload
jakkdl 893cc1c
Merge branch 'main' into disable_plugin_autoload_cli
jakkdl bfd049e
update comments in test, don't check __spec__ on pypy (????), add cha…
jakkdl 60becec
pemdas except not
jakkdl 48f4e2a
Apply suggestions from code review
jakkdl 98f940c
add parens
jakkdl b157cef
Simplify plugin name in test_installed_plugin_rewrite
nicoddemus 40d8ceb
Apply suggestions from code review
nicoddemus e7403ac
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| New flag: :ref:`--disable-plugin-autoload <disable_plugin_autoload>` which works as an alternative to :envvar:`PYTEST_DISABLE_PLUGIN_AUTOLOAD` when setting environment variables is inconvenient; and allows setting it in config files with :confval:`addopts`. |
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
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
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 |
|---|---|---|
|
|
@@ -218,10 +218,36 @@ def test_foo(pytestconfig): | |
| assert result.ret == 0 | ||
|
|
||
| @pytest.mark.parametrize("mode", ["plain", "rewrite"]) | ||
| @pytest.mark.parametrize("disable_plugin_autoload", ["env_var", "cli", ""]) | ||
| @pytest.mark.parametrize("explicit_specify", ["env_var", "cli", ""]) | ||
| def test_installed_plugin_rewrite( | ||
| self, pytester: Pytester, mode, monkeypatch | ||
| self, | ||
| pytester: Pytester, | ||
| mode: str, | ||
| monkeypatch: pytest.MonkeyPatch, | ||
| disable_plugin_autoload: str, | ||
| explicit_specify: str, | ||
| ) -> None: | ||
| monkeypatch.delenv("PYTEST_DISABLE_PLUGIN_AUTOLOAD", raising=False) | ||
| args = ["mainwrapper.py", "-s", f"--assert={mode}"] | ||
| if disable_plugin_autoload == "env_var": | ||
| monkeypatch.setenv("PYTEST_DISABLE_PLUGIN_AUTOLOAD", "1") | ||
| elif disable_plugin_autoload == "cli": | ||
| monkeypatch.delenv("PYTEST_DISABLE_PLUGIN_AUTOLOAD", raising=False) | ||
| args.append("--disable-plugin-autoload") | ||
| else: | ||
| assert disable_plugin_autoload == "" | ||
| monkeypatch.delenv("PYTEST_DISABLE_PLUGIN_AUTOLOAD", raising=False) | ||
|
|
||
| name = "spamplugin" | ||
|
|
||
| if explicit_specify == "env_var": | ||
| monkeypatch.setenv("PYTEST_PLUGINS", name) | ||
| elif explicit_specify == "cli": | ||
| args.append("-p") | ||
| args.append(name) | ||
| else: | ||
| assert explicit_specify == "" | ||
|
|
||
| # Make sure the hook is installed early enough so that plugins | ||
| # installed via distribution package are rewritten. | ||
| pytester.mkdir("hampkg") | ||
|
|
@@ -250,7 +276,7 @@ def check(values, value): | |
| import pytest | ||
|
|
||
| class DummyEntryPoint(object): | ||
| name = 'spam' | ||
| name = 'spamplugin' | ||
| module_name = 'spam.py' | ||
| group = 'pytest11' | ||
|
|
||
|
|
@@ -275,20 +301,29 @@ def test(check_first): | |
| check_first([10, 30], 30) | ||
|
|
||
| def test2(check_first2): | ||
| check_first([10, 30], 30) | ||
| check_first2([10, 30], 30) | ||
| """, | ||
| } | ||
| pytester.makepyfile(**contents) | ||
| result = pytester.run( | ||
| sys.executable, "mainwrapper.py", "-s", f"--assert={mode}" | ||
| ) | ||
| result = pytester.run(sys.executable, *args) | ||
| if mode == "plain": | ||
| expected = "E AssertionError" | ||
| elif mode == "rewrite": | ||
| expected = "*assert 10 == 30*" | ||
| else: | ||
| assert 0 | ||
| result.stdout.fnmatch_lines([expected]) | ||
|
|
||
| if not disable_plugin_autoload or explicit_specify: | ||
|
Member
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. With all the additional logic in this test, I wonder if it would be better to have a fixture for the |
||
| result.assert_outcomes(failed=2) | ||
| result.stdout.fnmatch_lines([expected, expected]) | ||
| else: | ||
| result.assert_outcomes(errors=2) | ||
| result.stdout.fnmatch_lines( | ||
| [ | ||
| "E fixture 'check_first' not found", | ||
| "E fixture 'check_first2' not found", | ||
| ] | ||
| ) | ||
|
|
||
| def test_rewrite_ast(self, pytester: Pytester) -> None: | ||
| pytester.mkdir("pkg") | ||
|
|
||
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.
Uh oh!
There was an error while loading. Please reload this page.