-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Changes from 2 commits
6a7958c
893cc1c
bfd049e
60becec
48f4e2a
98f940c
b157cef
40d8ceb
e7403ac
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -218,10 +218,40 @@ 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) | ||
|
|
||
| # FIXME: if it's already loaded then you get a ValueError: "Plugin already | ||
| # registered under a different name." | ||
| # vaguely related to https://github.com/pytest-dev/pytest/issues/5661 | ||
| name = "spamplugin" if disable_plugin_autoload else "spam" | ||
|
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. The difference here is that when loading via entry point, the plugin can choose its own name ( I have simplified things here by always using |
||
| # is there a single dotted name that can be used either way? idk | ||
|
|
||
| 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") | ||
|
|
@@ -275,20 +305,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") | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.