Coverage for tests / unit / tools / pytest_tool / test_json_parsing.py: 100%
22 statements
« prev ^ index » next coverage.py v7.13.0, created at 2026-04-03 18:53 +0000
« prev ^ index » next coverage.py v7.13.0, created at 2026-04-03 18:53 +0000
1"""Tests for pytest JSON output parsing."""
3from __future__ import annotations
5from assertpy import assert_that
7from lintro.parsers.pytest.pytest_parser import parse_pytest_json_output
9# =============================================================================
10# Tests for parse_pytest_json_output function
11# =============================================================================
14def test_parse_json_success_returns_empty(
15 mock_test_json_success: str,
16) -> None:
17 """Parse JSON with all passed returns empty list.
19 Args:
20 mock_test_json_success: Mock JSON string for successful tests.
21 """
22 issues = parse_pytest_json_output(mock_test_json_success)
23 # All tests passed, no failure/error/skipped issues
24 assert_that(issues).is_empty()
27def test_parse_json_failure_returns_issues(
28 mock_test_json_failure: str,
29) -> None:
30 """Parse JSON with failure returns issue list.
32 Args:
33 mock_test_json_failure: Mock JSON string for failed tests.
34 """
35 issues = parse_pytest_json_output(mock_test_json_failure)
36 assert_that(issues).is_length(1)
37 assert_that(issues[0].test_status).is_equal_to("FAILED")
38 assert_that(issues[0].test_name).is_equal_to("test_failure")
41def test_parse_json_mixed_returns_all_issues(
42 mock_test_json_mixed: str,
43) -> None:
44 """Parse JSON with mixed results returns all non-passing issues.
46 Args:
47 mock_test_json_mixed: Mock JSON string for mixed test results.
48 """
49 issues = parse_pytest_json_output(mock_test_json_mixed)
50 assert_that(issues).is_length(3) # failed, error, skipped
51 statuses = {issue.test_status for issue in issues}
52 assert_that(statuses).contains("FAILED", "ERROR", "SKIPPED")
55def test_parse_json_empty_returns_empty() -> None:
56 """Parse empty JSON returns empty list."""
57 issues = parse_pytest_json_output("")
58 assert_that(issues).is_empty()
61def test_parse_json_invalid_returns_empty() -> None:
62 """Parse invalid JSON returns empty list."""
63 issues = parse_pytest_json_output("not valid json")
64 assert_that(issues).is_empty()