From 5bc8eb01bc8975cf66a7f695ab4cc2a13719da20 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Tue, 31 Mar 2020 10:46:56 +0200 Subject: [PATCH] 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