Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use "worker" for compatibility with xdist >= 2.0 #412

Merged
merged 1 commit into from Jun 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS.rst
Expand Up @@ -38,3 +38,4 @@ Authors
* Hugo van Kemenade - https://github.com/hugovk
* Michael Manganiello - https://github.com/adamantike
* Anders Hovmöller - https://github.com/boxed
* Zac Hatfield-Dodds - https://zhd.dev
6 changes: 6 additions & 0 deletions CHANGELOG.rst
@@ -1,6 +1,12 @@
Changelog
=========

2.10.1 (2020-06-??)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

imho this should be a pytest-cov 3 release

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because it removes some compat.xxx names?

If compatibility with pytest-xdist <= 1.22 (from 2018) is really that important - and note that the oldest version pytest-cov is tested against is xdist 1.27 (from 2019) - I could add them back. @ionelmc?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's no harm in bumping the major version, but we don't have to make the decision in this PR

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We certainly don't want to extend the testing grid, it's way too big already.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As expected, old releases like pytest-xdist 1.22 account for very few downloads:

image

pepy.tech link

-------------------

* Support for ``pytest-xdist`` 2.0, which breaks compatibility with ``pytest-xdist`` before 1.22.3 (from 2017).
Contributed by Zac Hatfield-Dodds in `#412 <https://github.com/pytest-dev/pytest-cov/pull/412>`_.

2.10.0 (2020-06-12)
-------------------

Expand Down
19 changes: 0 additions & 19 deletions src/pytest_cov/compat.py
Expand Up @@ -29,22 +29,3 @@ def testsfailed(self):
@testsfailed.setter
def testsfailed(self, value):
setattr(self._session, self._attr, value)


def _attrgetter(attr):
"""
Return a callable object that fetches attr from its operand.

Unlike operator.attrgetter, the returned callable supports an extra two
arg form for a default.
"""
def fn(obj, *args):
return getattr(obj, attr, *args)

return fn


worker = 'slave' # for compatability with pytest-xdist<=1.22.0
workerid = worker + 'id'
workerinput = _attrgetter(worker + 'input')
workeroutput = _attrgetter(worker + 'output')
16 changes: 7 additions & 9 deletions src/pytest_cov/engine.py
Expand Up @@ -11,8 +11,6 @@
from coverage.data import CoverageData

from .compat import StringIO
from .compat import workerinput
from .compat import workeroutput
from .embed import cleanup


Expand Down Expand Up @@ -271,7 +269,7 @@ def start(self):
def configure_node(self, node):
"""Workers need to know if they are collocated and what files have moved."""

workerinput(node).update({
node.workerinput.update({
'cov_master_host': socket.gethostname(),
'cov_master_topdir': self.topdir,
'cov_master_rsync_roots': [str(root) for root in node.nodemanager.roots],
Expand All @@ -282,7 +280,7 @@ def testnodedown(self, node, error):

# If worker doesn't return any data then it is likely that this
# plugin didn't get activated on the worker side.
output = workeroutput(node, {})
output = getattr(node, 'workeroutput', {})
if 'cov_worker_node_id' not in output:
self.failed_workers.append(node)
return
Expand Down Expand Up @@ -341,12 +339,12 @@ def start(self):
cleanup()

# Determine whether we are collocated with master.
self.is_collocated = (socket.gethostname() == workerinput(self.config)['cov_master_host'] and
self.topdir == workerinput(self.config)['cov_master_topdir'])
self.is_collocated = (socket.gethostname() == self.config.workerinput['cov_master_host'] and
self.topdir == self.config.workerinput['cov_master_topdir'])

# If we are not collocated then rewrite master paths to worker paths.
if not self.is_collocated:
master_topdir = workerinput(self.config)['cov_master_topdir']
master_topdir = self.config.workerinput['cov_master_topdir']
worker_topdir = self.topdir
if self.cov_source is not None:
self.cov_source = [source.replace(master_topdir, worker_topdir)
Expand Down Expand Up @@ -375,7 +373,7 @@ def finish(self):

# If we are collocated then just inform the master of our
# data file to indicate that we have finished.
workeroutput(self.config)['cov_worker_node_id'] = self.nodeid
self.config.workeroutput['cov_worker_node_id'] = self.nodeid
else:
self.cov.combine()
self.cov.save()
Expand All @@ -391,7 +389,7 @@ def finish(self):
else:
data = self.cov.get_data().dumps()

workeroutput(self.config).update({
self.config.workeroutput.update({
'cov_worker_path': self.topdir,
'cov_worker_node_id': self.nodeid,
'cov_worker_data': data,
Expand Down
5 changes: 2 additions & 3 deletions src/pytest_cov/plugin.py
Expand Up @@ -203,7 +203,7 @@ class Config(object):
self.options.cov_fail_under = cov_config.fail_under

def _is_worker(self, session):
return compat.workerinput(session.config, None) is not None
return getattr(session.config, 'workerinput', None) is not None

def pytest_sessionstart(self, session):
"""At session start determine our implementation and delegate to it."""
Expand All @@ -220,8 +220,7 @@ def pytest_sessionstart(self, session):
self.pid = os.getpid()
if self._is_worker(session):
nodeid = (
compat.workerinput(session.config)
.get(compat.workerid, getattr(session, 'nodeid'))
session.config.workerinput.get('workerid', getattr(session, 'nodeid'))
)
self.start(engine.DistWorker, session.config, nodeid)
elif not self._started:
Expand Down
3 changes: 1 addition & 2 deletions tests/test_pytest_cov.py
Expand Up @@ -19,7 +19,6 @@
from six import exec_

import pytest_cov.plugin
from pytest_cov import compat

try:
from StringIO import StringIO
Expand All @@ -28,7 +27,7 @@

coverage, platform # required for skipif mark on test_cov_min_from_coveragerc

max_worker_restart_0 = "--max-" + compat.worker + "-restart=0"
max_worker_restart_0 = "--max-worker-restart=0"

SCRIPT = '''
import sys, helper
Expand Down