Skip to content

Commit 169fcec

Browse files
committed
fix(tests): power-cycle helper must run on Python 3.6, which CI uses
The two power-cycle lifetime tests kept FAILING in CI after being taught to skip, and the skip was never the problem: _emulator_process() -> subprocess.run(..., capture_output=True, text=True) TypeError: __init__() got an unexpected keyword argument 'capture_output' `capture_output=` and `text=` are Python 3.7+. The CI python-keepkey container runs 3.6, so the helper raised inside subprocess before any of its own logic -- including the skip added last commit -- could run. Locally it passed because this machine runs 3.10. Replaced all three uses with stdout=/stderr=PIPE plus universal_newlines, which 3.6 and 3.10 both understand, and recorded why in the docstring so nobody "modernises" it back. Also: a missing lsof now returns None instead of raising. That is the same situation as a remote emulator -- the harness cannot identify the process, let alone restart it -- so it belongs on the skip path, not the failure path. A green tree should not go red because a container lacks a tool. Worth stating for the next person: this failure was invisible locally in every run, and the previous fix looked correct precisely because it was tested on the wrong interpreter. The environment is part of the test. Local run (Python 3.10, harness owns the emulator): 6/6, both power-cycle tests executing rather than skipping.
1 parent a5df311 commit 169fcec

1 file changed

Lines changed: 18 additions & 8 deletions

File tree

tests/test_msg_session_trust_lifetime.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,17 +94,25 @@ def probe_blob():
9494
def _emulator_process(port):
9595
"""(pid, exe, cwd) of the process BOUND to udp/port, or None.
9696
97+
NOTE: subprocess.run(capture_output=/text=) is Python 3.7+. The CI test
98+
container runs 3.6, where passing them raises TypeError inside subprocess
99+
and this helper dies before any of its own logic runs -- which is why the
100+
power-cycle tests FAILED in CI instead of skipping. PIPE plus
101+
universal_newlines is the spelling both understand.
102+
97103
Skips this test client's own connected socket, which lsof also reports on
98104
the same port but as a `local->remote` pair rather than a bare bind.
99105
"""
100106
try:
101107
out = subprocess.run(['lsof', '-nP', '-iUDP:%d' % port, '-Fpn'],
102-
capture_output=True, text=True).stdout
103-
except FileNotFoundError:
104-
raise RuntimeError(
105-
"lsof is required to find and restart the emulator for the "
106-
"power-cycle tests; install it or run these against a device you "
107-
"can power-cycle by hand")
108+
stdout=subprocess.PIPE,
109+
stderr=subprocess.PIPE, universal_newlines=True).stdout
110+
except (FileNotFoundError, OSError):
111+
# No lsof: this harness cannot identify, let alone restart, the
112+
# emulator process -- the same situation as a remote one. Report "not
113+
# found" so _power_cycle() skips with its explanation, rather than
114+
# failing a green tree over a missing tool.
115+
return None
108116
pid = None
109117
for line in out.splitlines():
110118
if line.startswith('p'):
@@ -114,10 +122,12 @@ def _emulator_process(port):
114122
if '->' in name or not name.endswith(':%d' % port):
115123
continue
116124
exe = subprocess.run(['ps', '-o', 'comm=', '-p', str(pid)],
117-
capture_output=True, text=True).stdout.strip()
125+
stdout=subprocess.PIPE,
126+
stderr=subprocess.PIPE, universal_newlines=True).stdout.strip()
118127
cwd_out = subprocess.run(
119128
['lsof', '-a', '-p', str(pid), '-d', 'cwd', '-Fn'],
120-
capture_output=True, text=True).stdout
129+
stdout=subprocess.PIPE,
130+
stderr=subprocess.PIPE, universal_newlines=True).stdout
121131
cwd = None
122132
for cwd_line in cwd_out.splitlines():
123133
if cwd_line.startswith('n'):

0 commit comments

Comments
 (0)