Skip to content

Commit dd39f86

Browse files
committed
Tests: fix race condition in output
These tests (`testForIterable`, `testYieldNested`) consistently fail on my machine. I suspect this is because some output is printed stdout and some to stderr. Since the streams are not synchronized this is inherently racy.
1 parent fe15ee6 commit dd39f86

File tree

2 files changed

+13
-47
lines changed

2 files changed

+13
-47
lines changed

mypyc/test-data/run-generators.test

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ def generator() -> Generator[int, None, Union[int, None]]:
257257
yield 2
258258
yield 3
259259
except Exception as e:
260-
print_tb(wrapsys.exc_info()[2])
260+
print_tb(wrapsys.exc_info()[2], file=wrapsys.stdout)
261261
s = str(e)
262262
if s:
263263
print('caught exception with value ' + s)
@@ -294,6 +294,7 @@ from typing import Any
294294
import sys
295295
def exc_info() -> Any:
296296
return sys.exc_info() # type: ignore
297+
stdout: Any = sys.stdout # type: ignore
297298

298299
[file driver.py]
299300
import sys
@@ -348,24 +349,24 @@ with ctx_manager() as c:
348349
[out]
349350
File "native.py", line 10, in generator
350351
yield 3
352+
caught exception without value
351353
File "native.py", line 9, in generator
352354
yield 2
355+
caught exception with value some string
353356
File "native.py", line 8, in generator
354357
yield 1
355358
File "driver.py", line 31, in <module>
356359
raise Exception
360+
caught exception with value some other string
357361
File "native.py", line 10, in generator
358362
yield 3
359363
File "native.py", line 31, in wrapper
360364
return (yield from x)
365+
caught exception without value
361366
File "native.py", line 9, in generator
362367
yield 2
363368
File "native.py", line 31, in wrapper
364369
return (yield from x)
365-
caught exception without value
366-
caught exception with value some string
367-
caught exception with value some other string
368-
caught exception without value
369370
caught exception with value some string
370371
exception
371372
goodbye

mypyc/test-data/run-loops.test

Lines changed: 7 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ def iterate_over_tuple(iterable: Tuple[int, int, int]) -> None:
322322

323323
[file driver.py]
324324
from native import iterate_over_any, iterate_over_iterable, iterate_and_delete, sum_over_values, sum_over_even_values, sum_over_two_values, iterate_over_tuple
325-
import traceback
325+
import sys, traceback
326326
def broken_generator(n):
327327
num = 0
328328
while num < n:
@@ -338,61 +338,35 @@ print(sum_over_two_values(d))
338338
try:
339339
iterate_over_any(5)
340340
except TypeError:
341-
traceback.print_exc()
341+
traceback.print_exc(file=sys.stdout)
342342
try:
343343
iterate_over_iterable(broken_generator(5))
344344
except Exception:
345-
traceback.print_exc()
345+
traceback.print_exc(file=sys.stdout)
346346
try:
347347
iterate_and_delete(d)
348348
except RuntimeError:
349-
traceback.print_exc()
349+
traceback.print_exc(file=sys.stdout)
350350

351351
iterate_over_tuple((1, 2, 3))
352352
[out]
353+
15
354+
6
355+
3
353356
Traceback (most recent call last):
354357
File "driver.py", line 16, in <module>
355358
iterate_over_any(5)
356359
File "native.py", line 6, in iterate_over_any
357360
for element in a:
358361
TypeError: 'int' object is not iterable
359-
Traceback (most recent call last):
360-
File "driver.py", line 20, in <module>
361-
iterate_over_iterable(broken_generator(5))
362-
File "native.py", line 10, in iterate_over_iterable
363-
for element in iterable:
364-
File "driver.py", line 8, in broken_generator
365-
raise Exception('Exception Manually Raised')
366-
Exception: Exception Manually Raised
367-
Traceback (most recent call last):
368-
File "driver.py", line 24, in <module>
369-
iterate_and_delete(d)
370-
File "native.py", line 14, in iterate_and_delete
371-
for key in d:
372-
RuntimeError: dictionary changed size during iteration
373-
15
374-
6
375-
3
376362
0
377363
1
378364
2
379365
3
380366
4
381-
1
382-
2
383-
3
384-
[out version>=3.13]
385-
Traceback (most recent call last):
386-
File "driver.py", line 16, in <module>
387-
iterate_over_any(5)
388-
~~~~~~~~~~~~~~~~^^^
389-
File "native.py", line 6, in iterate_over_any
390-
for element in a:
391-
TypeError: 'int' object is not iterable
392367
Traceback (most recent call last):
393368
File "driver.py", line 20, in <module>
394369
iterate_over_iterable(broken_generator(5))
395-
~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^
396370
File "native.py", line 10, in iterate_over_iterable
397371
for element in iterable:
398372
File "driver.py", line 8, in broken_generator
@@ -401,18 +375,9 @@ Exception: Exception Manually Raised
401375
Traceback (most recent call last):
402376
File "driver.py", line 24, in <module>
403377
iterate_and_delete(d)
404-
~~~~~~~~~~~~~~~~~~^^^
405378
File "native.py", line 14, in iterate_and_delete
406379
for key in d:
407380
RuntimeError: dictionary changed size during iteration
408-
15
409-
6
410-
3
411-
0
412-
1
413-
2
414-
3
415-
4
416381
1
417382
2
418383
3

0 commit comments

Comments
 (0)