From b3b26d19dd0edcac2d10630e4133580b554d80c8 Mon Sep 17 00:00:00 2001 From: Peter Kovary Date: Thu, 20 Mar 2025 11:04:15 +0000 Subject: [PATCH 1/7] Add all pytester.plugins to runpytest_subprocess invocation Closes #13314 --- src/_pytest/pytester.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/_pytest/pytester.py b/src/_pytest/pytester.py index 59839562031..e2c54fc3cc6 100644 --- a/src/_pytest/pytester.py +++ b/src/_pytest/pytester.py @@ -1488,8 +1488,8 @@ def runpytest_subprocess( 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) + for plugin in reversed(plugins): + args = ("-p", plugin, *args) args = self._getpytestargs() + args return self.run(*args, timeout=timeout) From 57f8140ed0b10545f2c856201b531a419550b3ab Mon Sep 17 00:00:00 2001 From: Peter Kovary Date: Thu, 20 Mar 2025 11:09:46 +0000 Subject: [PATCH 2/7] Add myself to AUTHORS --- AUTHORS | 1 + 1 file changed, 1 insertion(+) 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 From 05934071a055b7a54116fd5b531f11c8b62f8a28 Mon Sep 17 00:00:00 2001 From: Peter Kovary Date: Thu, 20 Mar 2025 11:18:55 +0000 Subject: [PATCH 3/7] Create changelog/13314.bugfix.rst --- changelog/13314.bugfix.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog/13314.bugfix.rst diff --git a/changelog/13314.bugfix.rst b/changelog/13314.bugfix.rst new file mode 100644 index 00000000000..1c16cdfad20 --- /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. From 8791b663c0fb3097ba4277b8089af27ac4eaa843 Mon Sep 17 00:00:00 2001 From: Peter Kovary Date: Thu, 20 Mar 2025 11:20:18 +0000 Subject: [PATCH 4/7] Update 13314.bugfix.rst --- changelog/13314.bugfix.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog/13314.bugfix.rst b/changelog/13314.bugfix.rst index 1c16cdfad20..5cf454bd841 100644 --- a/changelog/13314.bugfix.rst +++ b/changelog/13314.bugfix.rst @@ -1 +1 @@ -Fix bug where `pytester.runpytest_subprocess` only included the first plugin from `pytester.plugins`. Now it correctly includes all of them. +Fix bug where ``pytester.runpytest_subprocess`` only included the first plugin from ``pytester.plugins``. Now it correctly includes all of them. From 3f1a1cb4875696cb0adb7908d595fe37dc39e8b8 Mon Sep 17 00:00:00 2001 From: Peter Kovary Date: Thu, 20 Mar 2025 11:29:01 +0000 Subject: [PATCH 5/7] Add test_pytester_subprocess_with_plugins --- testing/test_pytester.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/testing/test_pytester.py b/testing/test_pytester.py index 87714b4708f..508ebbc071d 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().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 From 4878019ba423de9df24cb1abc30ca3126d123662 Mon Sep 17 00:00:00 2001 From: Peter Kovary Date: Thu, 20 Mar 2025 11:57:53 +0000 Subject: [PATCH 6/7] Address lint --- testing/test_pytester.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testing/test_pytester.py b/testing/test_pytester.py index 508ebbc071d..058d210eef1 100644 --- a/testing/test_pytester.py +++ b/testing/test_pytester.py @@ -483,7 +483,7 @@ def test_plugins(pytestconfig): ) pytester.plugins.extend(["no:plug_1", "no:plug_2"]) - pytester.runpytest_subprocess().assert_outcomes(passed=1) + pytester.runpytest_subprocess(testfile).assert_outcomes(passed=1) def test_linematcher_with_nonlist() -> None: From 5c5926bd0a9ee8b562b39218167159f06ab70b0c Mon Sep 17 00:00:00 2001 From: Peter Kovary Date: Tue, 1 Apr 2025 14:18:02 +0100 Subject: [PATCH 7/7] Update Pytester.runpytest_subprocess to construct args as list --- src/_pytest/pytester.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/_pytest/pytester.py b/src/_pytest/pytester.py index e2c54fc3cc6..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)] - for plugin in reversed(plugins): - args = ("-p", plugin, *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.