@@ -112,22 +112,7 @@ def summarize_results(results):
112112 test_duration = f"{ test_duration :.2f} " if test_duration >= 0 else "N/A"
113113
114114 # Get test counts from test run
115- counts = {}
116- try :
117- # Remove ANSI color control characters
118- raw_output = ANSI_ESCAPE_RE .sub ("" , result ["test" ][0 ]["output" ])
119- # Read backwards through the output since the summary is at the bottom
120- output = reversed (list (raw_output .splitlines ()))
121- for line in output :
122- if match := PYTEST_SUMMARY_RE .match (line ):
123- counts = {
124- PYTEST_COUNT_NORMALIZE .get (name , name ): int (num )
125- for num , name in PYTEST_COUNT_RE .findall (match .group ("summary" ))
126- }
127- break
128-
129- except Exception :
130- pass
115+ counts = extract_pytest_counts (result )
131116
132117 summary .append (
133118 {
@@ -150,5 +135,26 @@ def summarize_results(results):
150135 return sorted (summary , key = lambda result : (1 if "OK" in result ["status" ] else 0 , result ["env_name" ]))
151136
152137
138+ def extract_pytest_counts (result ):
139+ # Trace through each tox command run backwards to find the pytest summary
140+ for command_results in reversed (result .get ("test" , [])):
141+ try :
142+ raw_output = command_results .get ("output" , "" )
143+ # Remove ANSI color control characters
144+ uncolored_output = ANSI_ESCAPE_RE .sub ("" , raw_output )
145+ # Read backwards through the output since the summary is at the bottom
146+ output = reversed (list (uncolored_output .splitlines ()))
147+ for line in output :
148+ if match := PYTEST_SUMMARY_RE .match (line ):
149+ return {
150+ PYTEST_COUNT_NORMALIZE .get (name , name ): int (num )
151+ for num , name in PYTEST_COUNT_RE .findall (match .group ("summary" ))
152+ }
153+ except Exception :
154+ pass
155+
156+ return {}
157+
158+
153159if __name__ == "__main__" :
154160 main ()
0 commit comments