Avoid unnecessary rinfo calls after creating gateways (#909)
Hopefully this fixes #907, as seems this is the only change in #901 which is somehow related. --------- Co-authored-by: Ronny Pfannschmidt <opensource@ronnypfannschmidt.de>
This commit is contained in:
5
changelog/907.bugfix.rst
Normal file
5
changelog/907.bugfix.rst
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
Avoid remote calls during startup as ``execnet`` by default does not ensure remote affinity with the
|
||||||
|
main thread and might accidentally schedule the pytest worker into a non-main thread, which breaks numerous frameworks,
|
||||||
|
for example ``asyncio``, ``anyio``, ``PyQt/PySide``, etc.
|
||||||
|
|
||||||
|
A more safe correction will require thread affinity in ``execnet`` (`pytest-dev/execnet#96 <https://github.com/pytest-dev/execnet/issues/96>`__).
|
||||||
@@ -444,26 +444,25 @@ class TerminalDistReporter:
|
|||||||
|
|
||||||
@pytest.hookimpl
|
@pytest.hookimpl
|
||||||
def pytest_xdist_newgateway(self, gateway) -> None:
|
def pytest_xdist_newgateway(self, gateway) -> None:
|
||||||
|
if self.config.option.verbose > 0:
|
||||||
rinfo = gateway._rinfo()
|
rinfo = gateway._rinfo()
|
||||||
is_local = rinfo.executable == sys.executable
|
different_interpreter = rinfo.executable != sys.executable
|
||||||
if self.config.option.verbose > 0 and not is_local:
|
if different_interpreter:
|
||||||
version = "%s.%s.%s" % rinfo.version_info[:3]
|
version = "%s.%s.%s" % rinfo.version_info[:3]
|
||||||
self.rewrite(
|
self.rewrite(
|
||||||
"[%s] %s Python %s cwd: %s"
|
f"[{gateway.id}] {rinfo.platform} Python {version} cwd: {rinfo.cwd}",
|
||||||
% (gateway.id, rinfo.platform, version, rinfo.cwd),
|
|
||||||
newline=True,
|
newline=True,
|
||||||
)
|
)
|
||||||
self.setstatus(gateway.spec, WorkerStatus.Initialized, tests_collected=0)
|
self.setstatus(gateway.spec, WorkerStatus.Initialized, tests_collected=0)
|
||||||
|
|
||||||
@pytest.hookimpl
|
@pytest.hookimpl
|
||||||
def pytest_testnodeready(self, node) -> None:
|
def pytest_testnodeready(self, node) -> None:
|
||||||
|
if self.config.option.verbose > 0:
|
||||||
d = node.workerinfo
|
d = node.workerinfo
|
||||||
is_local = d.get("executable") == sys.executable
|
different_interpreter = d.get("executable") != sys.executable
|
||||||
if self.config.option.verbose > 0 and not is_local:
|
if different_interpreter:
|
||||||
infoline = "[{}] Python {}".format(
|
version = d["version"].replace("\n", " -- ")
|
||||||
d["id"], d["version"].replace("\n", " -- ")
|
self.rewrite(f"[{d['id']}] Python {version}", newline=True)
|
||||||
)
|
|
||||||
self.rewrite(infoline, newline=True)
|
|
||||||
self.setstatus(
|
self.setstatus(
|
||||||
node.gateway.spec, WorkerStatus.ReadyForCollection, tests_collected=0
|
node.gateway.spec, WorkerStatus.ReadyForCollection, tests_collected=0
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user