Skip to content

Commit 6b96dc3

Browse files
authored
[3.14] Detect @reap_threads misuse (on a class) (#158937) (#159116)
Detect @reap_threads misuse (on a class) (#158937) (cherry picked from commit 565f76f)
1 parent 15045f4 commit 6b96dc3

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

‎Lib/test/support/threading_helper.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import _thread
22
import contextlib
33
import functools
4+
import inspect
45
import sys
56
import threading
67
import time
@@ -59,6 +60,11 @@ def reap_threads(func):
5960
"""Use this function when threads are being used. This will
6061
ensure that the threads are cleaned up even when the test fails.
6162
"""
63+
64+
if inspect.isclass(func):
65+
# It should be used on each test method, not on the whole class
66+
raise ValueError("@reap_threads is not compatible with classes")
67+
6268
@functools.wraps(func)
6369
def decorator(*args):
6470
key = threading_setup()

0 commit comments

Comments
 (0)