diff --git a/changelog/822.trivial.rst b/changelog/822.trivial.rst new file mode 100644 index 0000000..844453a --- /dev/null +++ b/changelog/822.trivial.rst @@ -0,0 +1 @@ +Replace internal usage of ``py.log`` with a custom solution (but with the same interface). diff --git a/src/xdist/dsession.py b/src/xdist/dsession.py index a950df6..ab8332f 100644 --- a/src/xdist/dsession.py +++ b/src/xdist/dsession.py @@ -1,6 +1,6 @@ -import py import pytest +from xdist.remote import Producer from xdist.workermanage import NodeManager from xdist.scheduler import ( EachScheduling, @@ -34,9 +34,7 @@ class DSession: def __init__(self, config): self.config = config - self.log = py.log.Producer("dsession") - if not config.option.debug: - py.log.setconsumer(self.log._keywords, None) + self.log = Producer("dsession", enabled=config.option.debug) self.nodemanager = None self.sched = None self.shuttingdown = False diff --git a/src/xdist/remote.py b/src/xdist/remote.py index 160b042..edf6ae3 100644 --- a/src/xdist/remote.py +++ b/src/xdist/remote.py @@ -9,8 +9,8 @@ import sys import os import time +from typing import Any -import py import pytest from execnet.gateway_base import dumps, DumpError @@ -24,6 +24,29 @@ except ImportError: pass +class Producer: + """ + Simplified implementation of the same interface as py.log, for backward compatibility + since we dropped the dependency on pylib. + Note: this is defined here because this module can't depend on xdist, so we need + to have the other way around. + """ + + def __init__(self, name: str, *, enabled: bool = True): + self.name = name + self.enabled = enabled + + def __repr__(self) -> str: + return f"{type(self).__name__}({self.name!r}, enabled={self.enabled})" + + def __call__(self, *a: Any, **k: Any) -> None: + if self.enabled: + print(f"[{self.name}]", *a, **k, file=sys.stderr) + + def __getattr__(self, name: str) -> "Producer": + return type(self)(name, enabled=self.enabled) + + def worker_title(title): try: setproctitle(title) @@ -37,9 +60,7 @@ class WorkerInteractor: self.config = config self.workerid = config.workerinput.get("workerid", "?") self.testrunuid = config.workerinput["testrunuid"] - self.log = py.log.Producer("worker-%s" % self.workerid) - if not config.option.debug: - py.log.setconsumer(self.log._keywords, None) + self.log = Producer(f"worker-{self.workerid}", enabled=config.option.debug) self.channel = channel config.pluginmanager.register(self) diff --git a/src/xdist/scheduler/each.py b/src/xdist/scheduler/each.py index cfe99e7..4579102 100644 --- a/src/xdist/scheduler/each.py +++ b/src/xdist/scheduler/each.py @@ -1,5 +1,4 @@ -from py.log import Producer - +from xdist.remote import Producer from xdist.workermanage import parse_spec_config from xdist.report import report_collection_diff diff --git a/src/xdist/scheduler/load.py b/src/xdist/scheduler/load.py index f3bef40..11d5309 100644 --- a/src/xdist/scheduler/load.py +++ b/src/xdist/scheduler/load.py @@ -1,8 +1,8 @@ from itertools import cycle -from py.log import Producer from _pytest.runner import CollectReport +from xdist.remote import Producer from xdist.workermanage import parse_spec_config from xdist.report import report_collection_diff diff --git a/src/xdist/scheduler/loadfile.py b/src/xdist/scheduler/loadfile.py index 867a94e..91b5938 100644 --- a/src/xdist/scheduler/loadfile.py +++ b/src/xdist/scheduler/loadfile.py @@ -1,5 +1,5 @@ from .loadscope import LoadScopeScheduling -from py.log import Producer +from xdist.remote import Producer class LoadFileScheduling(LoadScopeScheduling): diff --git a/src/xdist/scheduler/loadgroup.py b/src/xdist/scheduler/loadgroup.py index 072f64a..ecefa49 100644 --- a/src/xdist/scheduler/loadgroup.py +++ b/src/xdist/scheduler/loadgroup.py @@ -1,5 +1,5 @@ from .loadscope import LoadScopeScheduling -from py.log import Producer +from xdist.remote import Producer class LoadGroupScheduling(LoadScopeScheduling): diff --git a/src/xdist/scheduler/loadscope.py b/src/xdist/scheduler/loadscope.py index 69d9d9a..fabe1eb 100644 --- a/src/xdist/scheduler/loadscope.py +++ b/src/xdist/scheduler/loadscope.py @@ -1,7 +1,7 @@ from collections import OrderedDict from _pytest.runner import CollectReport -from py.log import Producer +from xdist.remote import Producer from xdist.report import report_collection_diff from xdist.workermanage import parse_spec_config diff --git a/src/xdist/workermanage.py b/src/xdist/workermanage.py index 504a7de..10f1a48 100644 --- a/src/xdist/workermanage.py +++ b/src/xdist/workermanage.py @@ -11,6 +11,7 @@ import pytest import execnet import xdist.remote +from xdist.remote import Producer from xdist.plugin import _sys_path @@ -246,9 +247,7 @@ class WorkerController: } self._down = False self._shutdown_sent = False - self.log = py.log.Producer("workerctl-%s" % gateway.id) - if not self.config.option.debug: - py.log.setconsumer(self.log._keywords, None) + self.log = Producer(f"workerctl-{gateway.id}", enabled=config.option.debug) def __repr__(self): return "<{} {}>".format(self.__class__.__name__, self.gateway.id)