Coverage for lintro / enums / pytest_enums.py: 100%
47 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"""Pytest-related enum definitions.
3This module defines enums for pytest special modes, output formats, and test statuses.
4"""
6from __future__ import annotations
8from enum import StrEnum, auto
11class TestStatus(StrEnum):
12 """Supported test status values.
14 Values are lower-case string identifiers (auto-generated from member names).
15 """
17 PASSED = auto()
18 FAILED = auto()
19 ERROR = auto()
20 SKIPPED = auto()
21 UNKNOWN = auto()
24class PytestSpecialMode(StrEnum):
25 """Supported special modes for pytest execution.
27 Values are lower-case string identifiers to align with pytest command-line options.
28 """
30 LIST_PLUGINS = auto()
31 CHECK_PLUGINS = auto()
32 COLLECT_ONLY = auto()
33 LIST_FIXTURES = auto()
34 FIXTURE_INFO = auto()
35 LIST_MARKERS = auto()
36 PARAMETRIZE_HELP = auto()
39class PytestOutputFormat(StrEnum):
40 """Supported output formats for pytest results.
42 Values are lower-case string identifiers to align with pytest options.
43 """
45 JSON = auto()
46 JUNIT = auto()
47 TEXT = auto()
50class PytestParallelPreset(StrEnum):
51 """Supported parallel execution presets for pytest-xdist.
53 Values are lower-case string identifiers for preset names.
54 """
56 AUTO = auto()
57 SMALL = auto()
58 MEDIUM = auto()
59 LARGE = auto()
62def normalize_pytest_special_mode(value: str | PytestSpecialMode) -> PytestSpecialMode:
63 """Normalize a raw value to a PytestSpecialMode enum.
65 Args:
66 value: str or PytestSpecialMode to normalize.
68 Returns:
69 PytestSpecialMode: Normalized enum value.
71 Raises:
72 ValueError: If value is not a valid special mode.
73 """
74 if isinstance(value, PytestSpecialMode):
75 return value
76 try:
77 return PytestSpecialMode[value.upper()]
78 except KeyError as err:
79 raise ValueError(
80 f"Unknown pytest special mode: {value!r}. "
81 f"Supported modes: {list(PytestSpecialMode)}",
82 ) from err
85def normalize_pytest_output_format(
86 value: str | PytestOutputFormat,
87) -> PytestOutputFormat:
88 """Normalize a raw value to a PytestOutputFormat enum.
90 Args:
91 value: str or PytestOutputFormat to normalize.
93 Returns:
94 PytestOutputFormat: Normalized enum value.
96 Raises:
97 ValueError: If value is not a valid output format.
98 """
99 if isinstance(value, PytestOutputFormat):
100 return value
101 try:
102 return PytestOutputFormat[value.upper()]
103 except KeyError as err:
104 raise ValueError(
105 f"Unknown pytest output format: {value!r}. "
106 f"Supported formats: {list(PytestOutputFormat)}",
107 ) from err
110def normalize_test_status(value: str | TestStatus) -> TestStatus:
111 """Normalize a raw value to a TestStatus enum.
113 Args:
114 value: str or TestStatus to normalize.
116 Returns:
117 TestStatus: Normalized enum value.
119 Raises:
120 ValueError: If value is not a valid test status.
121 """
122 if isinstance(value, TestStatus):
123 return value
124 try:
125 return TestStatus[value.upper()]
126 except KeyError as err:
127 supported = f"Supported statuses: {list(TestStatus)}"
128 raise ValueError(
129 f"Unknown test status: {value!r}. {supported}",
130 ) from err