Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ jobs:

- name: 🧪 Run tests with coverage
run: |
poetry run pytest --cov=pytest_reporter_plus tests/ --cov-fail-under=81 --cov-report=term
poetry run pytest --cov=pytest_reporter_plus tests/ --cov-fail-under=82 --cov-report=term
18 changes: 15 additions & 3 deletions tests/dummy_tests/test_cases.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@
def test_pass():
assert True

import sys

import pytest


@pytest.mark.flaky(reruns=1)
@pytest.mark.link("https://example.com/fail-trace")
@pytest.mark.xfail(reason="Expected failure for plugin test")
def test_fail():
print("stdout from fail")
print("stderr from fail", file=sys.stderr)
pytest.logs = "log from fail"
assert False


@pytest.mark.link("https://example.com/pass-trace")
@pytest.mark.flaky(reruns=1)
def test_pass():
print("stdout from pass")
print("stderr from pass", file=sys.stderr)
pytest.logs = "log from pass"
assert True


@pytest.mark.skip(reason="just skipping")
def test_skip():
pass
33 changes: 21 additions & 12 deletions tests/e2e/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,43 @@

def test_plugin_logs_expected_results():
with tempfile.TemporaryDirectory() as tmpdir:
output_file = os.path.join(tmpdir, "report.json")
report_path = os.path.join(tmpdir, "report.json")

result = subprocess.run(
[
"poetry", "run", "pytest",
"tests/dummy_tests",
"--capture-screenshots=none",
f"--json-report={output_file}"
f"--json-report={report_path}",
],
capture_output=True,
text=True
)

print("STDOUT IS:", result.stdout)
print("STDERR IS", result.stderr)
print("STDERR IS:", result.stderr)

assert os.path.exists(output_file), "Report not generated"
with open(output_file) as f:
data = json.load(f)
assert os.path.exists(report_path), "Report not generated"

with open(report_path) as f:
tests = json.load(f)

expected = {
"test_pass": "passed",
"test_fail": "skipped", # because it's xfail
"test_fail": "skipped",
"test_skip": "skipped",
}

for test_name, expected_status in expected.items():
actual_status = next((e["status"] for e in data if e["test"] == test_name), None)
assert actual_status == expected_status, (
f"{test_name} should be {expected_status}, got {actual_status}"
)
for test in tests:
name = test["test"]
expected_status = expected.get(name)
if expected_status:
assert test["status"] == expected_status, (
f"{name} should be {expected_status}, got {test['status']}"
)

assert "stdout" in test
assert "stderr" in test
assert "logs" in test
assert "links" in test
assert "flaky" in test