@@ -180,15 +180,10 @@ def _is_debugger_attached() -> bool:
180
180
return debugger .is_attached ()
181
181
182
182
183
- def _build_artifact_test_folder (
184
- pytestconfig : Any , request : pytest .FixtureRequest , folder_or_file_name : str
185
- ) -> str :
186
- output_dir = pytestconfig .getoption ("--output" )
187
- return os .path .join (
188
- output_dir ,
189
- _truncate_file_name (slugify (request .node .nodeid )),
190
- _truncate_file_name (folder_or_file_name ),
191
- )
183
+ @pytest .fixture
184
+ def output_path (pytestconfig : Any , request : pytest .FixtureRequest ) -> str :
185
+ output_dir = Path (pytestconfig .getoption ("--output" )).absolute ()
186
+ return os .path .join (output_dir , _truncate_file_name (slugify (request .node .nodeid )))
192
187
193
188
194
189
def _truncate_file_name (file_name : str ) -> str :
@@ -222,12 +217,13 @@ def browser_context_args(
222
217
@pytest .fixture ()
223
218
def _artifacts_recorder (
224
219
request : pytest .FixtureRequest ,
220
+ output_path : str ,
225
221
playwright : Playwright ,
226
222
pytestconfig : Any ,
227
223
_pw_artifacts_folder : tempfile .TemporaryDirectory ,
228
224
) -> Generator ["ArtifactsRecorder" , None , None ]:
229
225
artifacts_recorder = ArtifactsRecorder (
230
- pytestconfig , request , playwright , _pw_artifacts_folder
226
+ pytestconfig , request , output_path , playwright , _pw_artifacts_folder
231
227
)
232
228
yield artifacts_recorder
233
229
# If request.node is missing rep_call, then some error happened during execution
@@ -462,12 +458,14 @@ def __init__(
462
458
self ,
463
459
pytestconfig : Any ,
464
460
request : pytest .FixtureRequest ,
461
+ output_path : str ,
465
462
playwright : Playwright ,
466
463
pw_artifacts_folder : tempfile .TemporaryDirectory ,
467
464
) -> None :
468
465
self ._request = request
469
466
self ._pytestconfig = pytestconfig
470
467
self ._playwright = playwright
468
+ self ._output_path = output_path
471
469
self ._pw_artifacts_folder = pw_artifacts_folder
472
470
473
471
self ._all_pages : List [Page ] = []
@@ -476,6 +474,12 @@ def __init__(
476
474
self ._tracing_option = pytestconfig .getoption ("--tracing" )
477
475
self ._capture_trace = self ._tracing_option in ["on" , "retain-on-failure" ]
478
476
477
+ def _build_artifact_test_folder (self , folder_or_file_name : str ) -> str :
478
+ return os .path .join (
479
+ self ._output_path ,
480
+ _truncate_file_name (folder_or_file_name ),
481
+ )
482
+
479
483
def did_finish_test (self , failed : bool ) -> None :
480
484
screenshot_option = self ._pytestconfig .getoption ("--screenshot" )
481
485
capture_screenshot = screenshot_option == "on" or (
@@ -484,9 +488,7 @@ def did_finish_test(self, failed: bool) -> None:
484
488
if capture_screenshot :
485
489
for index , screenshot in enumerate (self ._screenshots ):
486
490
human_readable_status = "failed" if failed else "finished"
487
- screenshot_path = _build_artifact_test_folder (
488
- self ._pytestconfig ,
489
- self ._request ,
491
+ screenshot_path = self ._build_artifact_test_folder (
490
492
f"test-{ human_readable_status } -{ index + 1 } .png" ,
491
493
)
492
494
os .makedirs (os .path .dirname (screenshot_path ), exist_ok = True )
@@ -502,9 +504,7 @@ def did_finish_test(self, failed: bool) -> None:
502
504
trace_file_name = (
503
505
"trace.zip" if len (self ._traces ) == 1 else f"trace-{ index + 1 } .zip"
504
506
)
505
- trace_path = _build_artifact_test_folder (
506
- self ._pytestconfig , self ._request , trace_file_name
507
- )
507
+ trace_path = self ._build_artifact_test_folder (trace_file_name )
508
508
os .makedirs (os .path .dirname (trace_path ), exist_ok = True )
509
509
shutil .move (trace , trace_path )
510
510
else :
@@ -527,9 +527,7 @@ def did_finish_test(self, failed: bool) -> None:
527
527
else f"video-{ index + 1 } .webm"
528
528
)
529
529
video .save_as (
530
- path = _build_artifact_test_folder (
531
- self ._pytestconfig , self ._request , video_file_name
532
- )
530
+ path = self ._build_artifact_test_folder (video_file_name )
533
531
)
534
532
except Error :
535
533
# Silent catch empty videos.
0 commit comments