Skip to content

Commit 0d95679

Browse files
committed
Improve test_os robustness.
1 parent 1d3ec86 commit 0d95679

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

Lib/test/test_os.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4546,16 +4546,19 @@ def test_fork_warns_when_non_python_thread_exists(self):
45464546
warnings.filterwarnings(
45474547
"always", category=DeprecationWarning)
45484548
if os.fork() == 0:
4549-
assert len(ws) == 0 # Warn only the parent
4549+
assert not ws, f"unexpected warnings in child: {ws}"
45504550
os._exit(0) # child
45514551
else:
45524552
assert ws[0].category == DeprecationWarning, ws[0]
45534553
assert 'fork' in str(ws[0].message), ws[0]
4554+
# Waiting allows an error in the child to hit stderr.
4555+
exitcode = os.wait()[1]
4556+
assert exitcode == 0, f"child exited {exitcode}"
45544557
assert threading.active_count() == 1, threading.enumerate()
45554558
finally:
45564559
_end_spawned_pthread()
45574560
"""
4558-
_, out, err = assert_python_ok("-c", code)
4561+
_, out, err = assert_python_ok("-c", code, PYTHONOPTIMIZE='0')
45594562
self.assertEqual(err.decode("utf-8"), "")
45604563
self.assertEqual(out.decode("utf-8"), "")
45614564

0 commit comments

Comments
 (0)