Replace usages of py.log by custom implementation (#822)

Co-authored-by: Bruno Oliveira <nicoddemus@gmail.com>
This commit is contained in:
Anthony Sottile
2022-10-22 03:26:01 -07:00
committed by GitHub
parent 80130d59ea
commit 1471164197
9 changed files with 35 additions and 17 deletions

View File

@@ -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

View File

@@ -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)

View File

@@ -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

View File

@@ -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

View File

@@ -1,5 +1,5 @@
from .loadscope import LoadScopeScheduling
from py.log import Producer
from xdist.remote import Producer
class LoadFileScheduling(LoadScopeScheduling):

View File

@@ -1,5 +1,5 @@
from .loadscope import LoadScopeScheduling
from py.log import Producer
from xdist.remote import Producer
class LoadGroupScheduling(LoadScopeScheduling):

View File

@@ -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

View File

@@ -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)