1717SCREENSHOTS_DIR = os .path .join (os .path .dirname (__file__ ), "screenshots" )
1818os .makedirs (SCREENSHOTS_DIR , exist_ok = True )
1919
20+ # Create logs directory if it doesn't exist
21+ os .makedirs ("logs" , exist_ok = True )
22+
23+ # Report path constant (must match --html= in workflow)
24+ REPORT_PATH = os .path .join ("report" , "report.html" )
25+
2026
2127@pytest .fixture
2228def subtests (request ):
@@ -145,7 +151,7 @@ def pytest_runtest_makereport(item, call):
145151 # Use relative path from report.html location
146152 relative_path = os .path .relpath (
147153 screenshot_path ,
148- os .path .dirname (os .path .abspath ("report.html" ))
154+ os .path .dirname (os .path .abspath (REPORT_PATH ))
149155 )
150156
151157 # pytest-html expects this format for extras
@@ -163,9 +169,10 @@ def pytest_runtest_makereport(item, call):
163169 handler .flush ()
164170 log_output = stream .getvalue ()
165171
166- # Only remove the handler, don't close the stream yet
167- logger = logging .getLogger ()
168- logger .removeHandler (handler )
172+ # Only remove the handler on teardown phase so call-phase logs are captured
173+ if report .when == 'teardown' :
174+ logger = logging .getLogger ()
175+ logger .removeHandler (handler )
169176
170177 # Check if there are subtests
171178 subtests_html = ""
@@ -206,8 +213,9 @@ def pytest_runtest_makereport(item, call):
206213 else :
207214 report .description = f"<pre>{ log_output .strip ()} </pre>"
208215
209- # Clean up references
210- log_streams .pop (item .nodeid , None )
216+ # Clean up references only on teardown phase
217+ if report .when == 'teardown' :
218+ log_streams .pop (item .nodeid , None )
211219 else :
212220 report .description = ""
213221
@@ -232,7 +240,7 @@ def pytest_collection_modifyitems(items):
232240
233241def rename_duration_column ():
234242 """Rename Duration column to Execution Time in HTML report"""
235- report_path = os .path .abspath ("report.html" )
243+ report_path = os .path .abspath (REPORT_PATH )
236244 if not os .path .exists (report_path ):
237245 print ("Report file not found, skipping column rename." )
238246 return
0 commit comments