Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: collect artifacts on test setup/teardown #207

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
test: cover teardown edge cases; remove logs (#117)
storenth committed Feb 12, 2024
commit 50f951c8c5b47459fb10f4f478cea636582ab931
5 changes: 0 additions & 5 deletions pytest.ini

This file was deleted.

82 changes: 71 additions & 11 deletions tests/test_playwright.py
Original file line number Diff line number Diff line change
@@ -718,25 +718,34 @@ def test_failing(page, failed_setup_call):
)
result = testdir.runpytest(
"--screenshot",
"only-on-failure"
"only-on-failure",
"--video",
"retain-on-failure",
"--tracing",
"retain-on-failure",
)
result.assert_outcomes(errors=1)
test_results_dir = os.path.join(testdir.tmpdir, "test-results")

expected = [
{
"name": "test-artifacts-retain-on-setup-failure-py-test-failing-chromium",
"children": [
{
"name": re.compile(r".*webm"),
},
{
"name": "test-failed-1.png",
}
},
{
"name": "trace.zip",
},
],
}
]
_assert_folder_tree(test_results_dir, expected)

# request.config.teardown.failed = False
def test_artifacts_on_teardown(testdir: pytest.Testdir) -> None:

def test_artifacts_retain_on_teardown_failure(testdir: pytest.Testdir) -> None:
testdir.makepyfile(
"""
import pytest
@@ -751,25 +760,76 @@ def test_passing(page, failed_teardown_call):
)
result = testdir.runpytest(
"--screenshot",
"only-on-failure"
"only-on-failure",
"--video",
"retain-on-failure",
"--tracing",
"retain-on-failure",
)
result.assert_outcomes(passed=1, errors=1) # сделать чтобы скрин не сохранялся при успешном тесте (и все успешные тирдауны и сетапы)
result.assert_outcomes(passed=1, errors=1)
test_results_dir = os.path.join(testdir.tmpdir, "test-results")
print(f"{os.listdir(test_results_dir)=}")
print(os.listdir(f"{test_results_dir}/test-artifacts-on-teardown-py-test-passing-chromium"))
expected = [
{
"name": "test-artifacts-on-teardown-py-test-passing-chromium",
"name": "test-artifacts-retain-on-teardown-failure-py-test-passing-chromium",
"children": [
{
"name": re.compile(r".*webm"),
},
{
"name": "test-failed-1.png",
}
},
{
"name": "trace.zip",
},
],
}
]
_assert_folder_tree(test_results_dir, expected)


def test_empty_artifacts_on_teardown(testdir: pytest.Testdir) -> None:
testdir.makepyfile(
"""
import pytest
@pytest.fixture
def failed_teardown_call(page, request):
yield page
assert 2 == page.evaluate("1 + 1")

def test_passing(page, failed_teardown_call):
assert 2 == page.evaluate("1 + 1")
"""
)
result = testdir.runpytest(
"--screenshot",
"only-on-failure",
"--video",
"retain-on-failure",
"--tracing",
"retain-on-failure",
)
result.assert_outcomes(passed=1)
test_results_dir = os.path.join(testdir.tmpdir, "test-results")
expected = [
{
"name": "test-empty-artifacts-on-teardown-py-test-passing-chromium",
"children": [
{
"name": re.compile(r".*webm"),
},
{
"name": "test-failed-1.png",
},
{
"name": "trace.zip",
},
],
}
]
with pytest.raises(FileNotFoundError):
_assert_folder_tree(test_results_dir, expected)


def test_should_work_with_test_names_which_exceeds_256_characters(
testdir: pytest.Testdir,
) -> None: