-
-
Notifications
You must be signed in to change notification settings - Fork 33.1k
Closed
Labels
testsTests in the Lib/test dirTests in the Lib/test dirtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
Bug report
Seen locally. The with self.subTest():
is not safe to call from multiple threads concurrently because subTest
modifies self._subtest
, so you might end up with the wrong or None
subtest in the call to testPartExecutor
.
cpython/Lib/test/test_functools.py
Lines 1930 to 1942 in d372472
@threading_helper.requires_working_threading() | |
def test_lru_cache_threaded3(self): | |
@self.module.lru_cache(maxsize=2) | |
def f(x): | |
time.sleep(.01) | |
return 3 * x | |
def test(i, x): | |
with self.subTest(thread=i): | |
self.assertEqual(f(x), 3 * x, i) | |
threads = [threading.Thread(target=test, args=(i, v)) | |
for i, v in enumerate([1, 2, 2, 3, 2])] | |
with threading_helper.start_threads(threads): | |
pass |
Lines 553 to 566 in d372472
self._subtest = _SubTest(self, msg, params_map) | |
try: | |
with self._outcome.testPartExecutor(self._subtest, subTest=True): | |
yield | |
if not self._outcome.success: | |
result = self._outcome.result | |
if result is not None and result.failfast: | |
raise _ShouldStop | |
elif self._outcome.expectedFailure: | |
# If the test is expecting a failure, we really want to | |
# stop now and register the expected failure. | |
raise _ShouldStop | |
finally: | |
self._subtest = parent |
test_lru_cache_threaded3 (test.test_functools.TestLRUC.test_lru_cache_threaded3) ... Warning -- Uncaught thread exception: AttributeError
Exception in thread Thread-21 (test):
Traceback (most recent call last):
File "/raid/sgross/cpython/Lib/threading.py", line 1054, in _bootstrap_inner
self.run()
~~~~~~~~^^
File "/raid/sgross/cpython/Lib/threading.py", line 996, in run
self._target(*self._args, **self._kwargs)
~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/raid/sgross/cpython/Lib/test/test_functools.py", line 1937, in test
with self.subTest(thread=i):
~~~~~~~~~~~~^^^^^^^^^^
File "/raid/sgross/cpython/Lib/contextlib.py", line 148, in __exit__
next(self.gen)
~~~~^^^^^^^^^^
File "/raid/sgross/cpython/Lib/unittest/case.py", line 555, in subTest
with self._outcome.testPartExecutor(self._subtest, subTest=True):
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/raid/sgross/cpython/Lib/contextlib.py", line 148, in __exit__
next(self.gen)
~~~~^^^^^^^^^^
File "/raid/sgross/cpython/Lib/unittest/case.py", line 81, in testPartExecutor
self.result.addSubTest(test_case.test_case, test_case, None)
^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'test_case'
ok
Linked PRs
Metadata
Metadata
Assignees
Labels
testsTests in the Lib/test dirTests in the Lib/test dirtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error