Coverage for tests / unit / tools / pytest_tool / test_result_processor.py: 100%
27 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 PytestResultProcessor class."""
3from __future__ import annotations
5from typing import cast
7from assertpy import assert_that
9from lintro.parsers.pytest.pytest_issue import PytestIssue
10from lintro.tools.implementations.pytest.pytest_result_processor import (
11 PytestResultProcessor,
12)
14# =============================================================================
15# Tests for PytestResultProcessor class
16# =============================================================================
19def test_build_result_success(
20 result_processor: PytestResultProcessor,
21) -> None:
22 """Build result for successful test run.
24 Args:
25 result_processor: PytestResultProcessor instance for testing.
26 """
27 summary_data = {
28 "passed": 10,
29 "failed": 0,
30 "skipped": 0,
31 "error": 0,
32 "duration": 0.12,
33 "total": 10,
34 }
35 result = result_processor.build_result(
36 success=True,
37 summary_data=summary_data,
38 all_issues=[],
39 )
40 assert_that(result.success).is_true()
41 assert_that(result.name).is_equal_to("pytest")
42 assert_that(result.issues_count).is_equal_to(0)
45def test_build_result_failure(
46 result_processor: PytestResultProcessor,
47 sample_pytest_issues: list[PytestIssue],
48) -> None:
49 """Build result for failed test run.
51 Args:
52 result_processor: PytestResultProcessor instance for testing.
53 sample_pytest_issues: List of sample pytest issues for testing.
54 """
55 summary_data = {
56 "passed": 7,
57 "failed": 2,
58 "skipped": 1,
59 "error": 1,
60 "duration": 1.50,
61 "total": 10,
62 }
63 result = result_processor.build_result(
64 success=False,
65 summary_data=summary_data,
66 all_issues=sample_pytest_issues,
67 )
68 assert_that(result.success).is_false()
69 # Only FAILED and ERROR issues should be counted
70 assert_that(result.issues_count).is_equal_to(2)
73def test_build_result_filters_skipped(
74 result_processor: PytestResultProcessor,
75 sample_pytest_issues: list[PytestIssue],
76) -> None:
77 """Build result filters out SKIPPED from issues.
79 Args:
80 result_processor: PytestResultProcessor instance for testing.
81 sample_pytest_issues: List of sample pytest issues for testing.
82 """
83 summary_data = {
84 "passed": 7,
85 "failed": 1,
86 "skipped": 1,
87 "error": 1,
88 "duration": 1.50,
89 "total": 10,
90 }
91 result = result_processor.build_result(
92 success=False,
93 summary_data=summary_data,
94 all_issues=sample_pytest_issues,
95 )
96 # SKIPPED issues should not be in the result.issues
97 assert_that(result.issues).is_not_none()
98 issue_statuses = {
99 cast(PytestIssue, issue).test_status for issue in result.issues # type: ignore[union-attr]
100 }
101 assert_that(issue_statuses).does_not_contain("SKIPPED")
104def test_build_result_has_pytest_summary(
105 result_processor: PytestResultProcessor,
106) -> None:
107 """Build result includes pytest_summary.
109 Args:
110 result_processor: PytestResultProcessor instance for testing.
111 """
112 summary_data = {
113 "passed": 10,
114 "failed": 0,
115 "skipped": 0,
116 "error": 0,
117 "duration": 0.12,
118 "total": 10,
119 }
120 result = result_processor.build_result(
121 success=True,
122 summary_data=summary_data,
123 all_issues=[],
124 )
125 assert_that(result.pytest_summary).is_not_none()
126 assert_that(result.pytest_summary.get("passed")).is_equal_to(10) # type: ignore[union-attr]