From 5bc8eb01bc8975cf66a7f695ab4cc2a13719da20 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Tue, 31 Mar 2020 10:46:56 +0200 Subject: [PATCH 1/3] Fix passing `--basetemp` to subprocesses with pytest 5.4 Fixes https://github.com/pytest-dev/pytest-xdist/issues/510. Ref: https://github.com/pytest-dev/pytest/pull/6767 Also uses `--basetemp` with `-p no:tmpdir` as a good side effect (ref: https://github.com/pytest-dev/pytest-xdist/issues/22). --- changelog/510.bugfix.rst | 1 + src/xdist/workermanage.py | 10 ++++++---- testing/acceptance_test.py | 8 +++++--- 3 files changed, 12 insertions(+), 7 deletions(-) create mode 100644 changelog/510.bugfix.rst 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..b43325e3 100644 --- a/testing/acceptance_test.py +++ b/testing/acceptance_test.py @@ -766,9 +766,11 @@ def test_tmpdir_disabled(testdir): """ p1 = testdir.makepyfile( """ - def test_ok(): - pass - """ + def test_ok(request): + assert request.config.option.basetemp == {!r} + """.format( + str(testdir.tmpdir.dirpath() / "basetemp" / "popen-gw0") + ) ) result = testdir.runpytest(p1, "-n1", "-p", "no:tmpdir") assert result.ret == 0 From 845a52471224a9f903b8779740ce7be08a097ca5 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Tue, 31 Mar 2020 12:39:01 +0200 Subject: [PATCH 2/3] more tests --- testing/acceptance_test.py | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/testing/acceptance_test.py b/testing/acceptance_test.py index b43325e3..914a7efd 100644 --- a/testing/acceptance_test.py +++ b/testing/acceptance_test.py @@ -118,15 +118,20 @@ 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 + + def test_send2(tmpdir): + assert tmpdir.relto(py.path.local({!r})), tmpdir + """.format( + str(testdir.tmpdir), str(testdir.tmpdir), + ) ) - 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,15 +771,19 @@ def test_tmpdir_disabled(testdir): """ p1 = testdir.makepyfile( """ - def test_ok(request): + 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-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"]) From 2ac71e5d6c0d99a5942112a929add91f6b6a5e01 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Tue, 31 Mar 2020 15:02:03 +0200 Subject: [PATCH 3/3] extend test_basetemp_in_subprocesses --- testing/acceptance_test.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/testing/acceptance_test.py b/testing/acceptance_test.py index 914a7efd..d82d07e0 100644 --- a/testing/acceptance_test.py +++ b/testing/acceptance_test.py @@ -122,11 +122,22 @@ def test_basetemp_in_subprocesses(self, testdir): 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), + 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, "-n2")