diff --git a/changelog/510.bugfix.rst b/changelog/510.bugfix.rst new file mode 100644 index 00000000..e8bf309a --- /dev/null +++ b/changelog/510.bugfix.rst @@ -0,0 +1 @@ +Fix passing `--basetemp` to subprocesses with pytest 5.4. diff --git a/src/xdist/workermanage.py b/src/xdist/workermanage.py index af5241f1..65aef62f 100644 --- a/src/xdist/workermanage.py +++ b/src/xdist/workermanage.py @@ -1,12 +1,14 @@ from __future__ import print_function + import fnmatch import os import re import sys +import execnet import py import pytest -import execnet +from _pytest.tmpdir import TempPathFactory import xdist.remote @@ -252,9 +254,9 @@ def setup(self): args = make_reltoroot(self.nodemanager.roots, args) if spec.popen: name = "popen-%s" % self.gateway.id - if hasattr(self.config, "_tmpdirhandler"): - basetemp = self.config._tmpdirhandler.getbasetemp() - option_dict["basetemp"] = str(basetemp.join(name)) + basetemp = TempPathFactory.from_config(self.config).getbasetemp() + option_dict["basetemp"] = str(basetemp.joinpath(name)) + self.config.hook.pytest_configure_node(node=self) remote_module = self.config.hook.pytest_xdist_getremotemodule() diff --git a/testing/acceptance_test.py b/testing/acceptance_test.py index d93f08ed..d82d07e0 100644 --- a/testing/acceptance_test.py +++ b/testing/acceptance_test.py @@ -118,15 +118,31 @@ def test_fail2(): def test_basetemp_in_subprocesses(self, testdir): p1 = testdir.makepyfile( """ - def test_send(tmpdir): - import py - assert tmpdir.relto(py.path.local(%r)), tmpdir - """ - % str(testdir.tmpdir) + import py + + def test_send1(tmpdir): + assert tmpdir.relto(py.path.local({!r})), tmpdir + assert str(tmpdir) == {!r} + + def test_send2(tmpdir): + assert tmpdir.relto(py.path.local({!r})), tmpdir + assert str(tmpdir) == {!r} + """.format( + str(testdir.tmpdir), + str( + testdir.tmpdir.dirpath() + / "test_basetemp_in_subprocesses0/runpytest-0/popen-gw0/test_send10" + ), + str(testdir.tmpdir), + str( + testdir.tmpdir.dirpath() + / "test_basetemp_in_subprocesses0/runpytest-0/popen-gw1/test_send20" + ), + ) ) - result = testdir.runpytest_subprocess(p1, "-n1") + result = testdir.runpytest_subprocess(p1, "-n2") assert result.ret == 0 - result.stdout.fnmatch_lines(["*1 passed*"]) + result.stdout.fnmatch_lines(["* 2 passed in *"]) def test_dist_ini_specified(self, testdir): p1 = testdir.makepyfile( @@ -766,13 +782,19 @@ def test_tmpdir_disabled(testdir): """ p1 = testdir.makepyfile( """ - def test_ok(): - pass - """ + def test_ok1(request): + assert request.config.option.basetemp == {!r} + + def test_ok2(request): + assert request.config.option.basetemp == {!r} + """.format( + str(testdir.tmpdir.dirpath() / "basetemp" / "popen-gw0"), + str(testdir.tmpdir.dirpath() / "basetemp" / "popen-gw1"), + ) ) - result = testdir.runpytest(p1, "-n1", "-p", "no:tmpdir") + result = testdir.runpytest(p1, "-n2", "-p", "no:tmpdir") assert result.ret == 0 - result.stdout.fnmatch_lines("*1 passed*") + result.stdout.fnmatch_lines("* 2 passed in *") @pytest.mark.parametrize("plugin", ["xdist.looponfail", "xdist.boxed"])