diff --git a/AUTHORS b/AUTHORS index 95e6b13f11e..5fd86c4257e 100644 --- a/AUTHORS +++ b/AUTHORS @@ -345,6 +345,7 @@ Pavel Karateev Pavel Zhukov Paweł Adamczak Pedro Algarvio +Peter Kovary Petter Strandmark Philipp Loose Pierre Sassoulas diff --git a/changelog/13314.bugfix.rst b/changelog/13314.bugfix.rst new file mode 100644 index 00000000000..5cf454bd841 --- /dev/null +++ b/changelog/13314.bugfix.rst @@ -0,0 +1 @@ +Fix bug where ``pytester.runpytest_subprocess`` only included the first plugin from ``pytester.plugins``. Now it correctly includes all of them. diff --git a/src/_pytest/pytester.py b/src/_pytest/pytester.py index 59839562031..6d0d4eb28c1 100644 --- a/src/_pytest/pytester.py +++ b/src/_pytest/pytester.py @@ -1485,13 +1485,15 @@ def runpytest_subprocess( The result. """ __tracebackhide__ = True + pytest_args = list(self._getpytestargs()) + for plugin in self.plugins: + if isinstance(plugin, str): + pytest_args += ["-p", plugin] + p = make_numbered_dir(root=self.path, prefix="runpytest-", mode=0o700) - args = (f"--basetemp={p}", *args) - plugins = [x for x in self.plugins if isinstance(x, str)] - if plugins: - args = ("-p", plugins[0], *args) - args = self._getpytestargs() + args - return self.run(*args, timeout=timeout) + pytest_args.append(f"--basetemp={p}") + + return self.run(*pytest_args, *args, timeout=timeout) def spawn_pytest(self, string: str, expect_timeout: float = 10.0) -> pexpect.spawn: """Run pytest using pexpect. diff --git a/testing/test_pytester.py b/testing/test_pytester.py index 87714b4708f..058d210eef1 100644 --- a/testing/test_pytester.py +++ b/testing/test_pytester.py @@ -472,6 +472,20 @@ def test_timeout(): pytester.runpytest_subprocess(testfile, timeout=1) +def test_pytester_subprocess_with_plugins(pytester: Pytester) -> None: + testfile = pytester.makepyfile( + """ + def test_plugins(pytestconfig): + plugins = pytestconfig.pluginmanager.list_name_plugin() + assert ("plug_1", None) in plugins + assert ("plug_2", None) in plugins + """ + ) + pytester.plugins.extend(["no:plug_1", "no:plug_2"]) + + pytester.runpytest_subprocess(testfile).assert_outcomes(passed=1) + + def test_linematcher_with_nonlist() -> None: """Test LineMatcher with regard to passing in a set (accidentally).""" from _pytest._code.source import Source