Skip to content

Commit 50f951c

Browse files
committed
test: cover teardown edge cases; remove logs (microsoft#117)
1 parent 097bf59 commit 50f951c

File tree

2 files changed

+71
-16
lines changed

2 files changed

+71
-16
lines changed

pytest.ini

Lines changed: 0 additions & 5 deletions
This file was deleted.

tests/test_playwright.py

Lines changed: 71 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -718,25 +718,34 @@ def test_failing(page, failed_setup_call):
718718
)
719719
result = testdir.runpytest(
720720
"--screenshot",
721-
"only-on-failure"
721+
"only-on-failure",
722+
"--video",
723+
"retain-on-failure",
724+
"--tracing",
725+
"retain-on-failure",
722726
)
723727
result.assert_outcomes(errors=1)
724728
test_results_dir = os.path.join(testdir.tmpdir, "test-results")
725-
726729
expected = [
727730
{
728731
"name": "test-artifacts-retain-on-setup-failure-py-test-failing-chromium",
729732
"children": [
733+
{
734+
"name": re.compile(r".*webm"),
735+
},
730736
{
731737
"name": "test-failed-1.png",
732-
}
738+
},
739+
{
740+
"name": "trace.zip",
741+
},
733742
],
734743
}
735744
]
736745
_assert_folder_tree(test_results_dir, expected)
737746

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:
740749
testdir.makepyfile(
741750
"""
742751
import pytest
@@ -751,25 +760,76 @@ def test_passing(page, failed_teardown_call):
751760
)
752761
result = testdir.runpytest(
753762
"--screenshot",
754-
"only-on-failure"
763+
"only-on-failure",
764+
"--video",
765+
"retain-on-failure",
766+
"--tracing",
767+
"retain-on-failure",
755768
)
756-
result.assert_outcomes(passed=1, errors=1) # сделать чтобы скрин не сохранялся при успешном тесте (и все успешные тирдауны и сетапы)
769+
result.assert_outcomes(passed=1, errors=1)
757770
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"))
760771
expected = [
761772
{
762-
"name": "test-artifacts-on-teardown-py-test-passing-chromium",
773+
"name": "test-artifacts-retain-on-teardown-failure-py-test-passing-chromium",
763774
"children": [
775+
{
776+
"name": re.compile(r".*webm"),
777+
},
764778
{
765779
"name": "test-failed-1.png",
766-
}
780+
},
781+
{
782+
"name": "trace.zip",
783+
},
767784
],
768785
}
769786
]
770787
_assert_folder_tree(test_results_dir, expected)
771788

772789

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+
773833
def test_should_work_with_test_names_which_exceeds_256_characters(
774834
testdir: pytest.Testdir,
775835
) -> None:

0 commit comments

Comments
 (0)