Skip to content

Commit 29885b0

Browse files
committed
Avoid unnecessary rinfo calls after creating gateways
Hopefully this fixes #907, as seems this is the only change in #901 which is somehow related.
1 parent 52a6143 commit 29885b0

File tree

2 files changed

+17
-16
lines changed

2 files changed

+17
-16
lines changed

changelog/907.bugfix.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Avoid unnecessary remote calls during node startup, which might trigger a bug in execnet that causes
2+
tests to execute in threads other than the main thread.

src/xdist/dsession.py

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -444,26 +444,25 @@ def pytest_xdist_setupnodes(self, specs) -> None:
444444

445445
@pytest.hookimpl
446446
def pytest_xdist_newgateway(self, gateway) -> None:
447-
rinfo = gateway._rinfo()
448-
is_local = rinfo.executable == sys.executable
449-
if self.config.option.verbose > 0 and not is_local:
450-
version = "%s.%s.%s" % rinfo.version_info[:3]
451-
self.rewrite(
452-
"[%s] %s Python %s cwd: %s"
453-
% (gateway.id, rinfo.platform, version, rinfo.cwd),
454-
newline=True,
455-
)
447+
if self.config.option.verbose > 0:
448+
rinfo = gateway._rinfo()
449+
different_interpreter = rinfo.executable != sys.executable
450+
if different_interpreter:
451+
version = "%s.%s.%s" % rinfo.version_info[:3]
452+
self.rewrite(
453+
f"[{gateway.id}] {rinfo.platform} Python {version} cwd: {rinfo.cwd}",
454+
newline=True,
455+
)
456456
self.setstatus(gateway.spec, WorkerStatus.Initialized, tests_collected=0)
457457

458458
@pytest.hookimpl
459459
def pytest_testnodeready(self, node) -> None:
460-
d = node.workerinfo
461-
is_local = d.get("executable") == sys.executable
462-
if self.config.option.verbose > 0 and not is_local:
463-
infoline = "[{}] Python {}".format(
464-
d["id"], d["version"].replace("\n", " -- ")
465-
)
466-
self.rewrite(infoline, newline=True)
460+
if self.config.option.verbose > 0:
461+
d = node.workerinfo
462+
different_interpreter = d.get("executable") != sys.executable
463+
if different_interpreter:
464+
version = d["version"].replace("\n", " -- ")
465+
self.rewrite(f"[{d['id']}] Python {version}", newline=True)
467466
self.setstatus(
468467
node.gateway.spec, WorkerStatus.ReadyForCollection, tests_collected=0
469468
)

0 commit comments

Comments
 (0)