From fe1f23961269d6d0467ab7d013a895ef9d9cf941 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Mon, 23 Jul 2018 17:33:59 -0300 Subject: [PATCH] Remove last references to obsolete py.code Also remove some unnecessary references to py.builtin Fix #305 --- changelog/305.bugfix.rst | 3 +++ testing/test_remote.py | 4 ++-- testing/test_slavemanage.py | 3 ++- xdist/dsession.py | 6 +++--- xdist/looponfail.py | 6 +++--- xdist/report.py | 10 +++++----- xdist/workermanage.py | 12 +++++++----- 7 files changed, 25 insertions(+), 19 deletions(-) create mode 100644 changelog/305.bugfix.rst diff --git a/changelog/305.bugfix.rst b/changelog/305.bugfix.rst new file mode 100644 index 0000000..afb40f4 --- /dev/null +++ b/changelog/305.bugfix.rst @@ -0,0 +1,3 @@ +Remove last references to obsolete ``py.code``. + +Remove some unnecessary references to ``py.builtin``. diff --git a/testing/test_remote.py b/testing/test_remote.py index b0082d0..38369e9 100644 --- a/testing/test_remote.py +++ b/testing/test_remote.py @@ -6,7 +6,7 @@ from xdist.remote import serialize_report import execnet import marshal -queue = py.builtin._tryimport("queue", "Queue") +from six.moves.queue import Queue WAIT_TIMEOUT = 10.0 @@ -33,7 +33,7 @@ class WorkerSetup: def __init__(self, request, testdir): self.request = request self.testdir = testdir - self.events = queue.Queue() + self.events = Queue() def setup(self, ): self.testdir.chdir() diff --git a/testing/test_slavemanage.py b/testing/test_slavemanage.py index 3d239fa..0b11ae9 100644 --- a/testing/test_slavemanage.py +++ b/testing/test_slavemanage.py @@ -1,3 +1,4 @@ +from __future__ import print_function import py import pytest import textwrap @@ -170,7 +171,7 @@ class TestNodeManager: p, = nodemanager.gwmanager.multi_exec( "import os ; channel.send(os.getcwd())").receive_each() p = py.path.local(p) - py.builtin.print_("remote curdir", p) + print("remote curdir", p) assert p == mysetup.dest.join(config.topdir.basename) assert p.join("dir1").check() assert p.join("dir1", "file1").check() diff --git a/xdist/dsession.py b/xdist/dsession.py index 4503fcb..0b0b414 100644 --- a/xdist/dsession.py +++ b/xdist/dsession.py @@ -10,7 +10,7 @@ from xdist.scheduler import ( ) -queue = py.builtin._tryimport('queue', 'Queue') +from six.moves.queue import Empty, Queue class Interrupted(KeyboardInterrupt): @@ -41,7 +41,7 @@ class DSession(object): self.shuttingdown = False self.countfailures = 0 self.maxfail = config.getvalue("maxfail") - self.queue = queue.Queue() + self.queue = Queue() self._session = None self._failed_collection_errors = {} self._active_nodes = set() @@ -129,7 +129,7 @@ class DSession(object): try: eventcall = self.queue.get(timeout=2.0) break - except queue.Empty: + except Empty: continue callname, kwargs = eventcall assert callname, kwargs diff --git a/xdist/looponfail.py b/xdist/looponfail.py index 18275dc..de79592 100644 --- a/xdist/looponfail.py +++ b/xdist/looponfail.py @@ -6,7 +6,7 @@ processes) otherwise changes to source code can crash the controlling process which should best never happen. """ - +from __future__ import print_function import py import pytest import sys @@ -60,7 +60,7 @@ class RemoteControl(object): def trace(self, *args): if self.config.option.debug: msg = " ".join([str(x) for x in args]) - py.builtin.print_("RemoteControl:", msg) + print("RemoteControl:", msg) def initgateway(self): return execnet.makegateway("popen") @@ -248,7 +248,7 @@ class StatRecorder(object): if oldstat.mtime != curstat.mtime or \ oldstat.size != curstat.size: changed = True - py.builtin.print_("# MODIFIED", path) + print("# MODIFIED", path) if removepycfiles and path.ext == ".py": pycfile = path + "c" if pycfile.check(): diff --git a/xdist/report.py b/xdist/report.py index ae26ff7..e5a844b 100644 --- a/xdist/report.py +++ b/xdist/report.py @@ -1,4 +1,4 @@ -import py +from __future__ import print_function from difflib import unified_diff @@ -17,10 +17,10 @@ def report_collection_diff(from_collection, to_collection, from_id, to_id): fromfile=from_id, tofile=to_id, ) - error_message = py.builtin._totext( - 'Different tests were collected between {from_id} and {to_id}. ' - 'The difference is:\n' - '{diff}' + error_message = ( + u'Different tests were collected between {from_id} and {to_id}. ' + u'The difference is:\n' + u'{diff}' ).format(from_id=from_id, to_id=to_id, diff='\n'.join(diff)) msg = "\n".join([x.rstrip() for x in error_message.split("\n")]) return msg diff --git a/xdist/workermanage.py b/xdist/workermanage.py index 5069961..da7ecdf 100644 --- a/xdist/workermanage.py +++ b/xdist/workermanage.py @@ -1,3 +1,4 @@ +from __future__ import print_function import fnmatch import os import re @@ -6,6 +7,7 @@ import threading import py import pytest import execnet + import xdist.remote from _pytest import runner # XXX load dynamically @@ -48,7 +50,7 @@ class NodeManager(object): self.specs.append(spec) self.roots = self._getrsyncdirs() self.rsyncoptions = self._getrsyncoptions() - self._rsynced_specs = py.builtin.set() + self._rsynced_specs = set() def rsync_roots(self, gateway): """Rsync the set of roots to the node's gateway cwd.""" @@ -180,8 +182,7 @@ class HostRSync(execnet.RSync): if self._verbose: path = os.path.basename(self._sourcedir) + "/" + modified_rel_path remotepath = gateway.spec.chdir - py.builtin.print_('%s:%s <= %s' % - (gateway.spec, remotepath, path)) + print('%s:%s <= %s' % (gateway.spec, remotepath, path)) def make_reltoroot(roots, args): @@ -333,8 +334,9 @@ class WorkerController(object): # should not land in receiver-thread raise except: # noqa - excinfo = py.code.ExceptionInfo() - py.builtin.print_("!" * 20, excinfo) + from _pytest._code import ExceptionInfo + excinfo = ExceptionInfo() + print("!" * 20, excinfo) self.config.notify_exception(excinfo) self.shutdown() self.notify_inproc("errordown", node=self, error=excinfo)