From 443dc21061df08a67db2918363334f0d6840440f Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Mon, 13 Jul 2020 12:01:16 -0300 Subject: [PATCH] Fix rsyncdirs usage with pytest 6.0 Fix pytest-dev/pytest#7487 --- changelog/558.bugfix.rst | 1 + src/xdist/workermanage.py | 12 ++++++++++-- testing/acceptance_test.py | 1 - 3 files changed, 11 insertions(+), 3 deletions(-) create mode 100644 changelog/558.bugfix.rst diff --git a/changelog/558.bugfix.rst b/changelog/558.bugfix.rst new file mode 100644 index 00000000..b3bb0624 --- /dev/null +++ b/changelog/558.bugfix.rst @@ -0,0 +1 @@ +Fix ``rsyncdirs`` usage with pytest 6.0. diff --git a/src/xdist/workermanage.py b/src/xdist/workermanage.py index ff599f50..e8b49bb8 100644 --- a/src/xdist/workermanage.py +++ b/src/xdist/workermanage.py @@ -90,8 +90,16 @@ def _getrsyncdirs(self): import pytest import _pytest - pytestpath = pytest.__file__.rstrip("co") - pytestdir = py.path.local(_pytest.__file__).dirpath() + def get_dir(p): + """Return the directory path if p is a package or the path to the .py file otherwise.""" + stripped = p.rstrip("co") + if os.path.basename(stripped) == "__init__.py": + return os.path.dirname(p) + else: + return stripped + + pytestpath = get_dir(pytest.__file__) + pytestdir = get_dir(_pytest.__file__) config = self.config candidates = [py._pydir, pytestpath, pytestdir] candidates += config.option.rsyncdir diff --git a/testing/acceptance_test.py b/testing/acceptance_test.py index b6a4a949..bd6a2ca1 100644 --- a/testing/acceptance_test.py +++ b/testing/acceptance_test.py @@ -189,7 +189,6 @@ def test_crash(): ) assert result.ret == 1 - @pytest.mark.xfail(reason="#527: Ignore Python 3.8 failure for the time being") def test_distribution_rsyncdirs_example(self, testdir, monkeypatch): # use a custom plugin that has a custom command-line option to ensure # this is propagated to workers (see #491)