Skip to content

pytester: do not use outer plugins #4518

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

Closed
wants to merge 2 commits into from
Closed
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 src/_pytest/pytester.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
3 changes: 3 additions & 0 deletions testing/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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()

Expand Down
11 changes: 8 additions & 3 deletions testing/test_helpconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -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*"])


Expand Down
4 changes: 3 additions & 1 deletion testing/test_junitxml.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any idea about this?
I've assumed that -p xdist would work in general, but it looks like if it was loaded in the outer pytest already xdist does not contain the pytest_configure hook - likely because the entrypoint mapping is not considered anymore (from "xdist" to "xdist.plugin") - but why does it work here then?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the -p argument passes modules, not entrypoints, ever since xdist was split up to aid removing messy stuff that was no longer usable in that way

the xdist module itself no longer contains the hooks, different submodules do

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah.. but why is "-p xdist" enough here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/pytest-dev/pytest-xdist/blob/master/setup.py#L19 - it appears the xdist core plugin is named by entrypoint

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What confuses me here is that -p xdist.plugin is required in other places here, but -p xdist here. Likely some internal sys.path thing or similar..

suite_node = dom.find_first_by_tag("testsuite")
failed = []
for case_node in suite_node.find_by_tag("testcase"):
Expand Down
12 changes: 7 additions & 5 deletions testing/test_terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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):
Expand All @@ -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\]",
Expand Down Expand Up @@ -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%\]"])