From 213e1d934c200312eec5e8251a4de8041d200e23 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Sun, 9 Dec 2018 06:43:19 +0100 Subject: [PATCH 1/2] pytester: do not use outer plugins Sets PYTEST_DISABLE_PLUGIN_AUTOLOAD=1 by default. Fixes https://github.com/pytest-dev/pytest/issues/4351. --- src/_pytest/pytester.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/_pytest/pytester.py b/src/_pytest/pytester.py index c5962894845..0714ce2dff0 100644 --- a/src/_pytest/pytester.py +++ b/src/_pytest/pytester.py @@ -503,6 +503,7 @@ def __init__(self, request, tmpdir_factory): self.test_tmproot = tmpdir_factory.mktemp("tmp-" + name, numbered=True) os.environ["PYTEST_DEBUG_TEMPROOT"] = str(self.test_tmproot) os.environ.pop("TOX_ENV_DIR", None) # Ensure that it is not used for caching. + os.environ.setdefault("PYTEST_DISABLE_PLUGIN_AUTOLOAD", "1") self.plugins = [] self._cwd_snapshot = CwdSnapshot() self._sys_path_snapshot = SysPathsSnapshot() From 0b0770d55f2fc299666c7edc69be36a424f8197b Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Sun, 9 Dec 2018 10:51:24 +0100 Subject: [PATCH 2/2] fixup! pytester: do not use outer plugins --- testing/test_config.py | 3 +++ testing/test_helpconfig.py | 11 ++++++++--- testing/test_junitxml.py | 4 +++- testing/test_terminal.py | 12 +++++++----- 4 files changed, 21 insertions(+), 9 deletions(-) diff --git a/testing/test_config.py b/testing/test_config.py index 605d28aa0e4..e9271b04659 100644 --- a/testing/test_config.py +++ b/testing/test_config.py @@ -511,6 +511,7 @@ def test_f2(): assert 0 def test_preparse_ordering_with_setuptools(testdir, monkeypatch): pkg_resources = pytest.importorskip("pkg_resources") + monkeypatch.delenv("PYTEST_DISABLE_PLUGIN_AUTOLOAD") def my_iter(name): assert name == "pytest11" @@ -548,6 +549,7 @@ class PseudoPlugin(object): def test_setuptools_importerror_issue1479(testdir, monkeypatch): pkg_resources = pytest.importorskip("pkg_resources") + monkeypatch.delenv("PYTEST_DISABLE_PLUGIN_AUTOLOAD") def my_iter(name): assert name == "pytest11" @@ -576,6 +578,7 @@ def load(self): @pytest.mark.parametrize("block_it", [True, False]) def test_plugin_preparse_prevents_setuptools_loading(testdir, monkeypatch, block_it): pkg_resources = pytest.importorskip("pkg_resources") + monkeypatch.delenv("PYTEST_DISABLE_PLUGIN_AUTOLOAD") plugin_module_placeholder = object() diff --git a/testing/test_helpconfig.py b/testing/test_helpconfig.py index 9c7806d5489..7ec5e543bcd 100644 --- a/testing/test_helpconfig.py +++ b/testing/test_helpconfig.py @@ -6,14 +6,19 @@ from _pytest.main import EXIT_NOTESTSCOLLECTED -def test_version(testdir, pytestconfig): +@pytest.mark.parametrize("disable_plugin_autoload", (True, False)) +def test_version(disable_plugin_autoload, testdir, pytestconfig, monkeypatch): + if not disable_plugin_autoload: + monkeypatch.delenv("PYTEST_DISABLE_PLUGIN_AUTOLOAD") result = testdir.runpytest("--version") assert result.ret == 0 - # p = py.path.local(py.__file__).dirpath() result.stderr.fnmatch_lines( ["*pytest*{}*imported from*".format(pytest.__version__)] ) - if pytestconfig.pluginmanager.list_plugin_distinfo(): + if ( + not disable_plugin_autoload + and pytestconfig.pluginmanager.list_plugin_distinfo() + ): result.stderr.fnmatch_lines(["*setuptools registered plugins:", "*at*"]) diff --git a/testing/test_junitxml.py b/testing/test_junitxml.py index c9dc39f82b7..286b823895f 100644 --- a/testing/test_junitxml.py +++ b/testing/test_junitxml.py @@ -1046,7 +1046,9 @@ def test_x(i): assert i != 22 """ ) - _, dom = runandparse(testdir, "-n2") + # XXX: why does "-p xdist" work here, but xdist.plugin is required with + # other tests (to recognize the pytest_configure hook in there)?! + _, dom = runandparse(testdir, "-p xdist -n2") suite_node = dom.find_first_by_tag("testsuite") failed = [] for case_node in suite_node.find_by_tag("testcase"): diff --git a/testing/test_terminal.py b/testing/test_terminal.py index 86ec1cd07a6..f431fa4b223 100644 --- a/testing/test_terminal.py +++ b/testing/test_terminal.py @@ -616,7 +616,9 @@ def check(x): if not pytestconfig.pluginmanager.get_plugin("xdist"): pytest.skip("xdist plugin not installed") - result = testdir.runpytest(p1, "-v", "-n 1", SHOW_PYTEST_WARNINGS_ARG) + result = testdir.runpytest( + p1, "-v", "-p", "xdist.plugin", "-n 1", SHOW_PYTEST_WARNINGS_ARG + ) result.stdout.fnmatch_lines(["*FAIL*test_verbose_reporting.py::test_fail*"]) assert result.ret == 1 @@ -1333,7 +1335,7 @@ def test_verbose_count(self, many_tests_files, testdir): def test_xdist_normal(self, many_tests_files, testdir): pytest.importorskip("xdist") - output = testdir.runpytest("-n2") + output = testdir.runpytest("-p", "xdist.plugin", "-n2") output.stdout.re_match_lines([r"\.{20} \s+ \[100%\]"]) def test_xdist_normal_count(self, many_tests_files, testdir): @@ -1344,12 +1346,12 @@ def test_xdist_normal_count(self, many_tests_files, testdir): console_output_style = count """ ) - output = testdir.runpytest("-n2") + output = testdir.runpytest("-p", "xdist.plugin", "-n2") output.stdout.re_match_lines([r"\.{20} \s+ \[20/20\]"]) def test_xdist_verbose(self, many_tests_files, testdir): pytest.importorskip("xdist") - output = testdir.runpytest("-n2", "-v") + output = testdir.runpytest("-p", "xdist.plugin", "-n2", "-v") output.stdout.re_match_lines_random( [ r"\[gw\d\] \[\s*\d+%\] PASSED test_bar.py::test_bar\[1\]", @@ -1444,5 +1446,5 @@ def test_teardown_many_verbose(self, testdir, many_files): def test_xdist_normal(self, many_files, testdir): pytest.importorskip("xdist") - output = testdir.runpytest("-n2") + output = testdir.runpytest("-p", "xdist.plugin", "-n2") output.stdout.re_match_lines([r"[\.E]{40} \s+ \[100%\]"])