Skip to content

Fix 13314 add all plugins to pytester subprocess #13316

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

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,7 @@ Pavel Karateev
Pavel Zhukov
Paweł Adamczak
Pedro Algarvio
Peter Kovary
Petter Strandmark
Philipp Loose
Pierre Sassoulas
Expand Down
1 change: 1 addition & 0 deletions changelog/13314.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix bug where ``pytester.runpytest_subprocess`` only included the first plugin from ``pytester.plugins``. Now it correctly includes all of them.
14 changes: 8 additions & 6 deletions src/_pytest/pytester.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
14 changes: 14 additions & 0 deletions testing/test_pytester.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down