@@ -39,7 +39,7 @@ def target():
3939 return PeriodicExecutor (interval = interval , min_interval = min_interval , target = target , name = name )
4040
4141
42- class PeriodicExecutorTestBase (UnitTest ):
42+ class TestPeriodicExecutor (UnitTest ):
4343 def setUp (self ):
4444 self .executor = None
4545
@@ -48,14 +48,6 @@ def tearDown(self):
4848 self .executor .close ()
4949 self .executor .join (timeout = 2 )
5050
51-
52- class TestPeriodicExecutor (PeriodicExecutorTestBase ):
53- def test_repr_contains_class_and_name (self ):
54- executor = _make_executor (name = "exec" )
55- executor_repr = repr (executor )
56- self .assertIn ("PeriodicExecutor" , executor_repr )
57- self .assertIn ("exec" , executor_repr )
58-
5951 def test_join_without_open_is_safe (self ):
6052 self .executor = _make_executor ()
6153 try :
@@ -79,41 +71,25 @@ def target():
7971 self .assertTrue (ran .is_set (), "target never ran" )
8072
8173 def test_target_exception_stops_executor (self ):
82- if _IS_SYNC :
83- ran = threading .Event ()
84- captured_exc : list = []
85- orig_excepthook = threading .excepthook
86-
87- def _capture_excepthook (args ):
88- captured_exc .append (args .exc_value )
89-
90- threading .excepthook = _capture_excepthook
91- try :
92-
93- def target ():
94- ran .set ()
95- raise RuntimeError ("error" )
96-
97- self .executor = _make_executor (target = target )
98- self .executor .open ()
99- self .executor .join (timeout = 2 )
100- self .assertTrue (ran .is_set (), "target never ran" )
101- finally :
102- threading .excepthook = orig_excepthook
103- self .assertEqual (len (captured_exc ), 1 )
104- self .assertIsInstance (captured_exc [0 ], RuntimeError )
105- else :
106- call_count = 0
74+ call_count = 0
10775
108- def target ():
109- nonlocal call_count
110- call_count += 1
111- raise RuntimeError ("error" )
76+ def target ():
77+ nonlocal call_count
78+ call_count += 1
79+ raise RuntimeError ("error" )
11280
113- self .executor = _make_executor (target = target )
81+ self .executor = _make_executor (target = target )
82+ # Suppress threading.excepthook so the intentional RuntimeError raised
83+ # in the worker thread is not surfaced by pytest's threadexception
84+ # plugin (no-op for the async executor since no thread is involved).
85+ orig_excepthook = threading .excepthook
86+ threading .excepthook = lambda _args : None
87+ try :
11488 self .executor .open ()
11589 self .executor .join (timeout = 2 )
116- self .assertEqual (call_count , 1 , "target should stop after exception" )
90+ finally :
91+ threading .excepthook = orig_excepthook
92+ self .assertEqual (call_count , 1 , "target should stop after exception" )
11793
11894 def test_skip_sleep_flag_skips_interval (self ):
11995 call_times = []
0 commit comments