@@ -718,25 +718,34 @@ def test_failing(page, failed_setup_call):
718
718
)
719
719
result = testdir .runpytest (
720
720
"--screenshot" ,
721
- "only-on-failure"
721
+ "only-on-failure" ,
722
+ "--video" ,
723
+ "retain-on-failure" ,
724
+ "--tracing" ,
725
+ "retain-on-failure" ,
722
726
)
723
727
result .assert_outcomes (errors = 1 )
724
728
test_results_dir = os .path .join (testdir .tmpdir , "test-results" )
725
-
726
729
expected = [
727
730
{
728
731
"name" : "test-artifacts-retain-on-setup-failure-py-test-failing-chromium" ,
729
732
"children" : [
733
+ {
734
+ "name" : re .compile (r".*webm" ),
735
+ },
730
736
{
731
737
"name" : "test-failed-1.png" ,
732
- }
738
+ },
739
+ {
740
+ "name" : "trace.zip" ,
741
+ },
733
742
],
734
743
}
735
744
]
736
745
_assert_folder_tree (test_results_dir , expected )
737
746
738
- # request.config.teardown.failed = False
739
- def test_artifacts_on_teardown (testdir : pytest .Testdir ) -> None :
747
+
748
+ def test_artifacts_retain_on_teardown_failure (testdir : pytest .Testdir ) -> None :
740
749
testdir .makepyfile (
741
750
"""
742
751
import pytest
@@ -751,25 +760,76 @@ def test_passing(page, failed_teardown_call):
751
760
)
752
761
result = testdir .runpytest (
753
762
"--screenshot" ,
754
- "only-on-failure"
763
+ "only-on-failure" ,
764
+ "--video" ,
765
+ "retain-on-failure" ,
766
+ "--tracing" ,
767
+ "retain-on-failure" ,
755
768
)
756
- result .assert_outcomes (passed = 1 , errors = 1 ) # сделать чтобы скрин не сохранялся при успешном тесте (и все успешные тирдауны и сетапы)
769
+ result .assert_outcomes (passed = 1 , errors = 1 )
757
770
test_results_dir = os .path .join (testdir .tmpdir , "test-results" )
758
- print (f"{ os .listdir (test_results_dir )= } " )
759
- print (os .listdir (f"{ test_results_dir } /test-artifacts-on-teardown-py-test-passing-chromium" ))
760
771
expected = [
761
772
{
762
- "name" : "test-artifacts-on-teardown-py-test-passing-chromium" ,
773
+ "name" : "test-artifacts-retain- on-teardown-failure -py-test-passing-chromium" ,
763
774
"children" : [
775
+ {
776
+ "name" : re .compile (r".*webm" ),
777
+ },
764
778
{
765
779
"name" : "test-failed-1.png" ,
766
- }
780
+ },
781
+ {
782
+ "name" : "trace.zip" ,
783
+ },
767
784
],
768
785
}
769
786
]
770
787
_assert_folder_tree (test_results_dir , expected )
771
788
772
789
790
+ def test_empty_artifacts_on_teardown (testdir : pytest .Testdir ) -> None :
791
+ testdir .makepyfile (
792
+ """
793
+ import pytest
794
+ @pytest.fixture
795
+ def failed_teardown_call(page, request):
796
+ yield page
797
+ assert 2 == page.evaluate("1 + 1")
798
+
799
+ def test_passing(page, failed_teardown_call):
800
+ assert 2 == page.evaluate("1 + 1")
801
+ """
802
+ )
803
+ result = testdir .runpytest (
804
+ "--screenshot" ,
805
+ "only-on-failure" ,
806
+ "--video" ,
807
+ "retain-on-failure" ,
808
+ "--tracing" ,
809
+ "retain-on-failure" ,
810
+ )
811
+ result .assert_outcomes (passed = 1 )
812
+ test_results_dir = os .path .join (testdir .tmpdir , "test-results" )
813
+ expected = [
814
+ {
815
+ "name" : "test-empty-artifacts-on-teardown-py-test-passing-chromium" ,
816
+ "children" : [
817
+ {
818
+ "name" : re .compile (r".*webm" ),
819
+ },
820
+ {
821
+ "name" : "test-failed-1.png" ,
822
+ },
823
+ {
824
+ "name" : "trace.zip" ,
825
+ },
826
+ ],
827
+ }
828
+ ]
829
+ with pytest .raises (FileNotFoundError ):
830
+ _assert_folder_tree (test_results_dir , expected )
831
+
832
+
773
833
def test_should_work_with_test_names_which_exceeds_256_characters (
774
834
testdir : pytest .Testdir ,
775
835
) -> None :
0 commit comments