Accepting request 830842 from home:mcalabkova:branches:devel:languages:python:pytest

- Update to 2.1.0
  * New ``pytest_xdist_auto_num_workers`` hook can be implemented by plugins 
    or ``conftest.py`` files to control the number of workers when 
    ``--numprocesses=auto`` is given in the command-line.
  * ``psutil`` has proven to make ``pytest-xdist`` installation in certain 
    platforms and containers problematic, so to use it for automatic number 
    of CPUs detection users need to install the ``psutil`` extra
- Add patches to keep compatibility with older pytests:
  * reintroduce-slave-terminology.patch
  * 0001-Revert-Remove-compat-for-pytest-6.patch

OBS-URL: https://build.opensuse.org/request/show/830842
OBS-URL: https://build.opensuse.org/package/show/devel:languages:python:pytest/python-pytest-xdist?expand=0&rev=20
This commit is contained in:
Markéta Machová 2020-08-31 14:15:07 +00:00 committed by Git OBS Bridge
parent d98e85796a
commit e064f81a24
6 changed files with 283 additions and 7 deletions

View File

@ -0,0 +1,110 @@
From 9e81d88e5e9ac12cebc9848466560489b3064982 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Mark=C3=A9ta=20Cal=C3=A1bkov=C3=A1?=
<meggy.calabkova@gmail.com>
Date: Mon, 31 Aug 2020 15:50:54 +0200
Subject: [PATCH] Revert "Remove compat for pytest < 6"
This reverts commit d153e0a4c4b764c821da9907ba3d2cac31bc3884.
---
src/xdist/remote.py | 39 ++++++++++++++++++++++++++++----------
src/xdist/workermanage.py | 6 +++++-
testing/acceptance_test.py | 2 +-
3 files changed, 35 insertions(+), 12 deletions(-)
diff --git a/src/xdist/remote.py b/src/xdist/remote.py
index 26cf958..b78d744 100644
--- a/src/xdist/remote.py
+++ b/src/xdist/remote.py
@@ -11,6 +11,7 @@ import os
import time
import py
+import _pytest.hookspec
import pytest
from execnet.gateway_base import dumps, DumpError
@@ -100,8 +101,11 @@ class WorkerInteractor:
def pytest_runtest_logstart(self, nodeid, location):
self.sendevent("logstart", nodeid=nodeid, location=location)
- def pytest_runtest_logfinish(self, nodeid, location):
- self.sendevent("logfinish", nodeid=nodeid, location=location)
+ # the pytest_runtest_logfinish hook was introduced in pytest 3.4
+ if hasattr(_pytest.hookspec, "pytest_runtest_logfinish"):
+
+ def pytest_runtest_logfinish(self, nodeid, location):
+ self.sendevent("logfinish", nodeid=nodeid, location=location)
def pytest_runtest_logreport(self, report):
data = self.config.hook.pytest_report_to_serializable(
@@ -121,14 +125,29 @@ class WorkerInteractor:
)
self.sendevent("collectreport", data=data)
- def pytest_warning_recorded(self, warning_message, when, nodeid, location):
- self.sendevent(
- "warning_recorded",
- warning_message_data=serialize_warning_message(warning_message),
- when=when,
- nodeid=nodeid,
- location=location,
- )
+ # the pytest_warning_recorded hook was introduced in pytest 6.0
+ if hasattr(_pytest.hookspec, "pytest_warning_recorded"):
+
+ def pytest_warning_recorded(self, warning_message, when, nodeid, location):
+ self.sendevent(
+ "warning_recorded",
+ warning_message_data=serialize_warning_message(warning_message),
+ when=when,
+ nodeid=nodeid,
+ location=location,
+ )
+
+ # the pytest_warning_captured hook was introduced in pytest 3.8
+ elif hasattr(_pytest.hookspec, "pytest_warning_captured"):
+
+ def pytest_warning_captured(self, warning_message, when, item):
+ self.sendevent(
+ "warning_captured",
+ warning_message_data=serialize_warning_message(warning_message),
+ when=when,
+ # item cannot be serialized and will always be None when used with xdist
+ item=None,
+ )
def serialize_warning_message(warning_message):
diff --git a/src/xdist/workermanage.py b/src/xdist/workermanage.py
index 9b00251..141d86a 100644
--- a/src/xdist/workermanage.py
+++ b/src/xdist/workermanage.py
@@ -383,7 +383,11 @@ class WorkerController:
except: # noqa
from _pytest._code import ExceptionInfo
- excinfo = ExceptionInfo.from_current()
+ # ExceptionInfo API changed in pytest 4.1
+ if hasattr(ExceptionInfo, "from_current"):
+ excinfo = ExceptionInfo.from_current()
+ else:
+ excinfo = ExceptionInfo()
print("!" * 20, excinfo)
self.config.notify_exception(excinfo)
self.shutdown()
diff --git a/testing/acceptance_test.py b/testing/acceptance_test.py
index 8cac669..eee794c 100644
--- a/testing/acceptance_test.py
+++ b/testing/acceptance_test.py
@@ -1364,7 +1364,7 @@ def parse_tests_and_workers_from_output(lines):
r"""
\[(gw\d)\] # worker
\s*
- (?:\[\s*\d+%\])? # progress indicator
+ (?:\[\s*\d+%\])? # progress indicator (pytest >=3.3)
\s(.*?) # status string ("PASSED")
\s(.*::.*) # nodeid
""",
--
2.28.0

View File

@ -1,3 +0,0 @@
version https://git-lfs.github.com/spec/v1
oid sha256:3217b1f40290570bf27b1f82714fc4ed44c3260ba9b2f6cde0372378fc707ad3
size 65663

View File

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:82d938f1a24186520e2d9d3a64ef7d9ac7ecdf1a0659e095d18e596b8cbd0672
size 66332

View File

@ -1,3 +1,17 @@
-------------------------------------------------------------------
Mon Aug 31 13:01:20 UTC 2020 - Marketa Calabkova <mcalabkova@suse.com>
- Update to 2.1.0
* New ``pytest_xdist_auto_num_workers`` hook can be implemented by plugins
or ``conftest.py`` files to control the number of workers when
``--numprocesses=auto`` is given in the command-line.
* ``psutil`` has proven to make ``pytest-xdist`` installation in certain
platforms and containers problematic, so to use it for automatic number
of CPUs detection users need to install the ``psutil`` extra
- Add patches to keep compatibility with older pytests:
* reintroduce-slave-terminology.patch
* 0001-Revert-Remove-compat-for-pytest-6.patch
-------------------------------------------------------------------
Tue Aug 25 08:12:22 UTC 2020 - Marketa Calabkova <mcalabkova@suse.com>

View File

@ -19,24 +19,30 @@
%{?!python_module:%define python_module() python-%{**} python3-%{**}}
%define skip_python2 1
Name: python-pytest-xdist
Version: 2.0.0
Version: 2.1.0
Release: 0
Summary: Distributed testing and loop-on-failing for py.test
License: MIT
URL: https://github.com/pytest-dev/pytest-xdist
Source0: https://files.pythonhosted.org/packages/source/p/pytest-xdist/pytest-xdist-%{version}.tar.gz
# This is actually revert of something upstream wanted to do a long time ago, but was waiting for the rest of pytest to sync with them.
# It is only a terminology change, but one that has personal meaning for many people. On the other hand, it was breaking compatibility with pytest < 6.
# In my opinion it would be inadequate to send this patch upstream.
Patch0: reintroduce-slave-terminology.patch
# minor compatibility revert
Patch1: 0001-Revert-Remove-compat-for-pytest-6.patch
BuildRequires: %{python_module execnet >= 1.1}
BuildRequires: %{python_module filelock}
BuildRequires: %{python_module psutil >= 3.0.0}
BuildRequires: %{python_module pytest >= 6.0.0}
BuildRequires: %{python_module pytest >= 4.4.0}
BuildRequires: %{python_module pytest-forked}
BuildRequires: %{python_module setuptools_scm}
BuildRequires: fdupes
BuildRequires: python-rpm-macros
Requires: python-execnet >= 1.1
Requires: python-psutil >= 3.0.0
Requires: python-pytest >= 6.0.0
Requires: python-pytest >= 4.4.0
Requires: python-pytest-forked
Suggests: python-psutil >= 3.0.0
BuildArch: noarch
%python_subpackages
@ -66,6 +72,7 @@ You may specify different Python versions and interpreters.
%prep
%setup -q -n pytest-xdist-%{version}
%autopatch -p1
sed -i 's/\r//' README.rst
%build

View File

@ -0,0 +1,145 @@
From ae74dc2172d7f633d2e52d30aec79fbb0ae9ed63 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Mark=C3=A9ta=20Cal=C3=A1bkov=C3=A1?=
<meggy.calabkova@gmail.com>
Date: Mon, 31 Aug 2020 15:26:22 +0200
Subject: [PATCH] Revert "Finish removal of "slave" terminology"
This reverts commit de3e54fd278d49b9b5d64e64f5942512519545e5.
---
.appveyor.yml | 1 +
.travis.yml | 2 ++
setup.py | 10 ++++++----
src/xdist/dsession.py | 3 +++
src/xdist/plugin.py | 5 ++++-
src/xdist/remote.py | 3 +++
src/xdist/workermanage.py | 6 +++++-
testing/acceptance_test.py | 16 ++++++++++++++++
tox.ini | 4 ++++
9 files changed, 44 insertions(+), 6 deletions(-)
diff --git a/setup.py b/setup.py
index b6fb0f1..560069c 100644
--- a/setup.py
+++ b/setup.py
@@ -1,6 +1,6 @@
from setuptools import setup, find_packages
-install_requires = ["execnet>=1.1", "pytest>=6.0.0", "pytest-forked"]
+install_requires = ["execnet>=1.1", "pytest>=4.4.0", "pytest-forked"]
with open("README.rst") as f:
@@ -9,7 +9,8 @@ with open("README.rst") as f:
setup(
name="pytest-xdist",
use_scm_version={"write_to": "src/xdist/_version.py"},
- description="pytest xdist plugin for distributed testing and loop-on-failing modes",
+ description="pytest xdist plugin for distributed testing"
+ " and loop-on-failing modes",
long_description=long_description,
license="MIT",
author="holger krekel and contributors",
diff --git a/src/xdist/dsession.py b/src/xdist/dsession.py
index 07ef091..80edd9b 100644
--- a/src/xdist/dsession.py
+++ b/src/xdist/dsession.py
@@ -150,6 +150,9 @@ class DSession:
node.workerinfo["id"] = node.gateway.id
node.workerinfo["spec"] = node.gateway.spec
+ # TODO: (#234 task) needs this for pytest. Remove when refactor in pytest repo
+ node.slaveinfo = node.workerinfo
+
self.config.hook.pytest_testnodeready(node=node)
if self.shuttingdown:
node.shutdown()
diff --git a/src/xdist/plugin.py b/src/xdist/plugin.py
index 2d8424d..f497603 100644
--- a/src/xdist/plugin.py
+++ b/src/xdist/plugin.py
@@ -65,11 +65,14 @@ def pytest_addoption(parser):
)
group.addoption(
"--max-worker-restart",
+ "--max-slave-restart",
action="store",
default=None,
dest="maxworkerrestart",
help="maximum number of workers that can be restarted "
- "when crashed (set to zero to disable this feature)",
+ "when crashed (set to zero to disable this feature)\n"
+ "'--max-slave-restart' option is deprecated and will be removed in "
+ "a future release",
)
group.addoption(
"--dist",
diff --git a/src/xdist/remote.py b/src/xdist/remote.py
index 97dc180..26cf958 100644
--- a/src/xdist/remote.py
+++ b/src/xdist/remote.py
@@ -233,5 +233,8 @@ if __name__ == "__channelexec__":
config._parser.prog = os.path.basename(workerinput["mainargv"][0])
config.workerinput = workerinput
config.workeroutput = {}
+ # TODO: deprecated name, backward compatibility only. Remove it in future
+ config.slaveinput = config.workerinput
+ config.slaveoutput = config.workeroutput
interactor = WorkerInteractor(config, channel)
config.hook.pytest_cmdline_main(config=config)
diff --git a/src/xdist/workermanage.py b/src/xdist/workermanage.py
index dfcb59b..9b00251 100644
--- a/src/xdist/workermanage.py
+++ b/src/xdist/workermanage.py
@@ -225,9 +225,13 @@ class WorkerController:
self.workerinput = {
"workerid": gateway.id,
"workercount": len(nodemanager.specs),
+ "slaveid": gateway.id,
+ "slavecount": len(nodemanager.specs),
"testrunuid": nodemanager.testrunuid,
"mainargv": sys.argv,
}
+ # TODO: deprecated name, backward compatibility only. Remove it in future
+ self.slaveinput = self.workerinput
self._down = False
self._shutdown_sent = False
self.log = py.log.Producer("workerctl-%s" % gateway.id)
@@ -326,7 +330,7 @@ class WorkerController:
self.notify_inproc(eventname, node=self, **kwargs)
elif eventname == "workerfinished":
self._down = True
- self.workeroutput = kwargs["workeroutput"]
+ self.workeroutput = self.slaveoutput = kwargs["workeroutput"]
self.notify_inproc("workerfinished", node=self)
elif eventname in ("logstart", "logfinish"):
self.notify_inproc(eventname, node=self, **kwargs)
diff --git a/testing/acceptance_test.py b/testing/acceptance_test.py
index 48ed35f..8cac669 100644
--- a/testing/acceptance_test.py
+++ b/testing/acceptance_test.py
@@ -241,6 +241,22 @@ class TestDistribution:
result.stderr.fnmatch_lines(["--foobar=123 active! *"])
assert dest.join(subdir.basename).check(dir=1)
+ def test_backward_compatibility_worker_terminology(self, testdir):
+ """Ensure that we still support "config.slaveinput" for backward compatibility (#234).
+
+ Keep in mind that removing this compatibility will break a ton of plugins and user code.
+ """
+ testdir.makepyfile(
+ """
+ def test(pytestconfig):
+ assert hasattr(pytestconfig, 'slaveinput')
+ assert hasattr(pytestconfig, 'workerinput')
+ """
+ )
+ result = testdir.runpytest("-n1")
+ result.stdout.fnmatch_lines("*1 passed*")
+ assert result.ret == 0
+
def test_data_exchange(self, testdir):
testdir.makeconftest(
"""
--
2.28.0