Skip to content

Commit 54c70bc

Browse files
authored
Merge pull request #4878 from blueyed/fix-test_crash_on_closing_tmpfile_py27
tests: make test_crash_on_closing_tmpfile_py27 more reliable
2 parents f3f6cb2 + 83558a0 commit 54c70bc

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

testing/test_capture.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1403,28 +1403,36 @@ def test_capattr():
14031403

14041404

14051405
def test_crash_on_closing_tmpfile_py27(testdir):
1406-
testdir.makepyfile(
1406+
p = testdir.makepyfile(
14071407
"""
14081408
from __future__ import print_function
1409-
import time
14101409
import threading
14111410
import sys
14121411
1412+
printing = threading.Event()
1413+
14131414
def spam():
14141415
f = sys.stderr
1416+
print('SPAMBEFORE', end='', file=f)
1417+
printing.set()
1418+
14151419
while True:
1416-
print('.', end='', file=f)
1420+
try:
1421+
f.flush()
1422+
except (OSError, ValueError):
1423+
break
14171424
1418-
def test_silly():
1425+
def test_spam_in_thread():
14191426
t = threading.Thread(target=spam)
14201427
t.daemon = True
14211428
t.start()
1422-
time.sleep(0.5)
14231429
1430+
printing.wait()
14241431
"""
14251432
)
1426-
result = testdir.runpytest_subprocess()
1433+
result = testdir.runpytest_subprocess(str(p))
14271434
assert result.ret == 0
1435+
assert result.stderr.str() == ""
14281436
assert "IOError" not in result.stdout.str()
14291437

14301438

0 commit comments

Comments
 (0)