@@ -181,61 +181,66 @@ def test_confcutdir(self, testdir):
181
181
@pytest .mark .parametrize (
182
182
"ini_file_text, invalid_keys, warning_output, exception_text" ,
183
183
[
184
- (
184
+ pytest . param (
185
185
"""
186
- [pytest]
187
- unknown_ini = value1
188
- another_unknown_ini = value2
189
- """ ,
186
+ [pytest]
187
+ unknown_ini = value1
188
+ another_unknown_ini = value2
189
+ """ ,
190
190
["unknown_ini" , "another_unknown_ini" ],
191
191
[
192
192
"=*= warnings summary =*=" ,
193
193
"*PytestConfigWarning:*Unknown config option: another_unknown_ini" ,
194
194
"*PytestConfigWarning:*Unknown config option: unknown_ini" ,
195
195
],
196
196
"Unknown config option: another_unknown_ini" ,
197
+ id = "2-unknowns" ,
197
198
),
198
- (
199
+ pytest . param (
199
200
"""
200
- [pytest]
201
- unknown_ini = value1
202
- minversion = 5.0.0
203
- """ ,
201
+ [pytest]
202
+ unknown_ini = value1
203
+ minversion = 5.0.0
204
+ """ ,
204
205
["unknown_ini" ],
205
206
[
206
207
"=*= warnings summary =*=" ,
207
208
"*PytestConfigWarning:*Unknown config option: unknown_ini" ,
208
209
],
209
210
"Unknown config option: unknown_ini" ,
211
+ id = "1-unknown" ,
210
212
),
211
- (
213
+ pytest . param (
212
214
"""
213
- [some_other_header]
214
- unknown_ini = value1
215
- [pytest]
216
- minversion = 5.0.0
217
- """ ,
215
+ [some_other_header]
216
+ unknown_ini = value1
217
+ [pytest]
218
+ minversion = 5.0.0
219
+ """ ,
218
220
[],
219
221
[],
220
222
"" ,
223
+ id = "unknown-in-other-header" ,
221
224
),
222
- (
225
+ pytest . param (
223
226
"""
224
- [pytest]
225
- minversion = 5.0.0
226
- """ ,
227
+ [pytest]
228
+ minversion = 5.0.0
229
+ """ ,
227
230
[],
228
231
[],
229
232
"" ,
233
+ id = "no-unknowns" ,
230
234
),
231
- (
235
+ pytest . param (
232
236
"""
233
- [pytest]
234
- conftest_ini_key = 1
235
- """ ,
237
+ [pytest]
238
+ conftest_ini_key = 1
239
+ """ ,
236
240
[],
237
241
[],
238
242
"" ,
243
+ id = "1-known" ,
239
244
),
240
245
],
241
246
)
@@ -247,19 +252,24 @@ def test_invalid_config_options(
247
252
"""
248
253
def pytest_addoption(parser):
249
254
parser.addini("conftest_ini_key", "")
250
- """
255
+ """
251
256
)
252
- testdir .tmpdir .join ("pytest.ini" ).write (textwrap .dedent (ini_file_text ))
257
+ testdir .makepyfile ("def test(): pass" )
258
+ testdir .makeini (ini_file_text )
253
259
254
260
config = testdir .parseconfig ()
255
261
assert sorted (config ._get_unknown_ini_keys ()) == sorted (invalid_keys )
256
262
257
263
result = testdir .runpytest ()
258
264
result .stdout .fnmatch_lines (warning_output )
259
265
266
+ result = testdir .runpytest ("--strict-config" )
260
267
if exception_text :
261
- result = testdir .runpytest ("--strict-config" )
262
- result .stdout .fnmatch_lines ("INTERNALERROR>*" + exception_text )
268
+ result .stderr .fnmatch_lines ("ERROR: " + exception_text )
269
+ assert result .ret == pytest .ExitCode .USAGE_ERROR
270
+ else :
271
+ result .stderr .no_fnmatch_line (exception_text )
272
+ assert result .ret == pytest .ExitCode .OK
263
273
264
274
@pytest .mark .filterwarnings ("default" )
265
275
def test_silence_unknown_key_warning (self , testdir : Testdir ) -> None :
0 commit comments