@@ -88,6 +88,71 @@ def test_collect_once():
8888 pytest .fail ("Unable to find MainThread" )
8989
9090
91+ def _find_sleep_event (events , class_name ):
92+ class_method_found = False
93+ class_classmethod_found = False
94+
95+ for e in events :
96+ for frame in e .frames :
97+ if frame [0 ] == __file__ .replace (".pyc" , ".py" ) and frame [2 ] == "sleep_class" and frame [3 ] == class_name :
98+ class_method_found = True
99+ elif (
100+ frame [0 ] == __file__ .replace (".pyc" , ".py" ) and frame [2 ] == "sleep_instance" and frame [3 ] == class_name
101+ ):
102+ class_classmethod_found = True
103+
104+ if class_method_found and class_classmethod_found :
105+ return True
106+
107+ return False
108+
109+
110+ def test_collect_once_with_class ():
111+ class SomeClass (object ):
112+ @classmethod
113+ def sleep_class (cls ):
114+ # type: (...) -> bool
115+ return cls ().sleep_instance ()
116+
117+ def sleep_instance (self ):
118+ # type: (...) -> bool
119+ for _ in range (5 ):
120+ if _find_sleep_event (r .events [stack_event .StackSampleEvent ], "SomeClass" ):
121+ return True
122+ nogevent .sleep (1 )
123+ return False
124+
125+ r = recorder .Recorder ()
126+ s = stack .StackCollector (r )
127+
128+ with s :
129+ assert SomeClass .sleep_class ()
130+
131+
132+ def test_collect_once_with_class_not_right_type ():
133+ # type: (...) -> None
134+ r = recorder .Recorder ()
135+
136+ class SomeClass (object ):
137+ @classmethod
138+ def sleep_class (foobar , cls ):
139+ # type: (...) -> bool
140+ return foobar ().sleep_instance (cls )
141+
142+ def sleep_instance (foobar , self ):
143+ # type: (...) -> bool
144+ for _ in range (5 ):
145+ if _find_sleep_event (r .events [stack_event .StackSampleEvent ], "" ):
146+ return True
147+ nogevent .sleep (1 )
148+ return False
149+
150+ s = stack .StackCollector (r )
151+
152+ with s :
153+ assert SomeClass .sleep_class (123 )
154+
155+
91156def _fib (n ):
92157 if n == 1 :
93158 return 1
@@ -309,7 +374,7 @@ def test_exception_collection_threads():
309374 assert e .sampling_period > 0
310375 assert e .thread_id in {t .ident for t in threads }
311376 assert isinstance (e .thread_name , str )
312- assert e .frames == [("<string>" , 5 , "_f30" )]
377+ assert e .frames == [("<string>" , 5 , "_f30" , "" )]
313378 assert e .nframes == 1
314379 assert e .exc_type == ValueError
315380 for t in threads :
@@ -333,7 +398,7 @@ def test_exception_collection():
333398 assert e .sampling_period > 0
334399 assert e .thread_id == nogevent .thread_get_ident ()
335400 assert e .thread_name == "MainThread"
336- assert e .frames == [(__file__ , 327 , "test_exception_collection" )]
401+ assert e .frames == [(__file__ , 392 , "test_exception_collection" , " " )]
337402 assert e .nframes == 1
338403 assert e .exc_type == ValueError
339404
@@ -365,7 +430,7 @@ def test_exception_collection_trace(
365430 assert e .sampling_period > 0
366431 assert e .thread_id == nogevent .thread_get_ident ()
367432 assert e .thread_name == "MainThread"
368- assert e .frames == [(__file__ , 354 , "test_exception_collection_trace" )]
433+ assert e .frames == [(__file__ , 419 , "test_exception_collection_trace" , " " )]
369434 assert e .nframes == 1
370435 assert e .exc_type == ValueError
371436 assert e .span_id == span .span_id
@@ -647,7 +712,7 @@ def _nothing():
647712 else :
648713 main_thread_found = True
649714 elif event .task_id in {t .ident for t in threads }:
650- for filename , lineno , funcname in event .frames :
715+ for filename , lineno , funcname , classname in event .frames :
651716 if funcname in (
652717 "_nothing" ,
653718 "sleep" ,
0 commit comments