Skip to content

Commit 260b671

Browse files
committed
Constantify test_handle_force_color_no_color_reporters
Instead of runtime-generating it each time Signed-off-by: Stavros Ntentos <[email protected]>
1 parent a2afa05 commit 260b671

File tree

1 file changed

+19
-43
lines changed

1 file changed

+19
-43
lines changed

tests/lint/test_pylinter.py

Lines changed: 19 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@
77
import io
88
import os
99
import sys
10-
import warnings
1110
from pathlib import Path
12-
from typing import Any, NoReturn
11+
from typing import Any, NamedTuple, NoReturn
1312
from unittest import mock
1413
from unittest.mock import patch
1514

@@ -88,49 +87,21 @@ def test_open_pylinter_prefer_stubs(linter: PyLinter) -> None:
8887
MANAGER.prefer_stubs = False
8988

9089

91-
def pytest_generate_tests(metafunc: pytest.Metafunc) -> None:
92-
if metafunc.function.__name__ != test_handle_force_color_no_color.__name__:
93-
return
90+
class ReportersCombo(NamedTuple):
91+
text_reporters: tuple[str, ...]
92+
colorized_reporters: tuple[str, ...]
9493

95-
if (
96-
TEXT_REPORTERS not in metafunc.fixturenames
97-
or COLORIZED_REPORTERS not in metafunc.fixturenames
98-
):
99-
warnings.warn(
100-
f"Missing fixture {TEXT_REPORTERS} or {COLORIZED_REPORTERS} in"
101-
f" {test_handle_force_color_no_color.function.__name__}??",
102-
stacklevel=2,
103-
)
104-
return
105-
106-
parameters = []
107-
108-
reporter_combinations = [
109-
("file", STDOUT_TEXT),
110-
("file",),
111-
(STDOUT_TEXT,),
112-
("",),
113-
]
114-
115-
for tr in list(reporter_combinations):
116-
for cr in list(reporter_combinations):
117-
tr = tuple(t for t in tr if t)
118-
cr = tuple(t for t in cr if t)
119-
120-
total_reporters = len(tr) + len(cr)
121-
unique_reporters = len(set(tr + cr))
12294

123-
if total_reporters == 0:
124-
continue
125-
126-
if unique_reporters != total_reporters:
127-
continue
128-
129-
parameters.append((tuple(tr), tuple(cr)))
130-
131-
metafunc.parametrize(
132-
f"{TEXT_REPORTERS}, {COLORIZED_REPORTERS}", parameters, ids=repr
133-
)
95+
test_handle_force_color_no_color_reporters = (
96+
ReportersCombo(("file", "stdout"), ()),
97+
ReportersCombo(("file",), ("stdout",)),
98+
ReportersCombo(("file",), ()),
99+
ReportersCombo(("stdout",), ("file",)),
100+
ReportersCombo(("stdout",), ()),
101+
ReportersCombo((), ("file", "stdout")),
102+
ReportersCombo((), ("file",)),
103+
ReportersCombo((), ("stdout",)),
104+
)
134105

135106

136107
@pytest.mark.parametrize(
@@ -143,6 +114,11 @@ def pytest_generate_tests(metafunc: pytest.Metafunc) -> None:
143114
[True, False],
144115
ids=lambda force_color: f"{force_color=}",
145116
)
117+
@pytest.mark.parametrize(
118+
"text_reporters, colorized_reporters",
119+
test_handle_force_color_no_color_reporters,
120+
ids=repr,
121+
)
146122
def test_handle_force_color_no_color(
147123
monkeypatch: pytest.MonkeyPatch,
148124
recwarn: pytest.WarningsRecorder,

0 commit comments

Comments
 (0)