7
7
import io
8
8
import os
9
9
import sys
10
- import warnings
11
10
from pathlib import Path
12
- from typing import Any , NoReturn
11
+ from typing import Any , NamedTuple , NoReturn
13
12
from unittest import mock
14
13
from unittest .mock import patch
15
14
@@ -88,49 +87,21 @@ def test_open_pylinter_prefer_stubs(linter: PyLinter) -> None:
88
87
MANAGER .prefer_stubs = False
89
88
90
89
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 , ...]
94
93
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 ))
122
94
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
+ )
134
105
135
106
136
107
@pytest .mark .parametrize (
@@ -143,6 +114,11 @@ def pytest_generate_tests(metafunc: pytest.Metafunc) -> None:
143
114
[True , False ],
144
115
ids = lambda force_color : f"{ force_color = } " ,
145
116
)
117
+ @pytest .mark .parametrize (
118
+ "text_reporters, colorized_reporters" ,
119
+ test_handle_force_color_no_color_reporters ,
120
+ ids = repr ,
121
+ )
146
122
def test_handle_force_color_no_color (
147
123
monkeypatch : pytest .MonkeyPatch ,
148
124
recwarn : pytest .WarningsRecorder ,
0 commit comments