1
1
import os
2
2
from collections import defaultdict
3
- from typing import Any , Dict , Mapping , Optional , Sequence , Tuple
3
+ from typing import Any , Dict , List , Mapping , Optional , Sequence , Tuple
4
4
5
5
from _pytest .config import Config
6
6
from _pytest .config .argparsing import Parser
@@ -100,6 +100,13 @@ def pytest_addoption(parser: Parser) -> None:
100
100
help = Option .MD_REPORT_FLAVOR .help_msg
101
101
+ HelpMsg .EXTRA_MSG_TEMPLATE .format (Option .MD_REPORT_FLAVOR .envvar_str ),
102
102
)
103
+ group .addoption (
104
+ Option .MD_EXCLUDE_OUTCOMES .cmdoption_str ,
105
+ nargs = "+" ,
106
+ default = [],
107
+ help = Option .MD_EXCLUDE_OUTCOMES .help_msg
108
+ + HelpMsg .EXTRA_MSG_TEMPLATE .format (Option .MD_EXCLUDE_OUTCOMES .envvar_str ),
109
+ )
103
110
104
111
parser .addini (
105
112
Option .MD_REPORT .inioption_str ,
@@ -157,6 +164,12 @@ def pytest_addoption(parser: Parser) -> None:
157
164
default = None ,
158
165
help = Option .MD_REPORT_FLAVOR .help_msg ,
159
166
)
167
+ parser .addini (
168
+ Option .MD_EXCLUDE_OUTCOMES .inioption_str ,
169
+ type = "args" ,
170
+ default = [],
171
+ help = Option .MD_EXCLUDE_OUTCOMES .help_msg ,
172
+ )
160
173
161
174
162
175
def is_make_md_report (config : Config ) -> bool :
@@ -298,6 +311,33 @@ def retrieve_md_flavor(config: Config) -> MarkdownFlavor:
298
311
return normalize_md_flavor (str (md_flavor ))
299
312
300
313
314
+ def retrieve_exclude_outcomes (config : Config ) -> List [str ]:
315
+ def norm_names (names : Sequence [Any ]) -> List [str ]:
316
+ return [str (name ).lower ().strip () for name in names ]
317
+
318
+ exclude_outcomes = config .option .md_report_exclude_outcomes
319
+
320
+ if not exclude_outcomes :
321
+ exclude_outcomes = os .environ .get (Option .MD_EXCLUDE_OUTCOMES .envvar_str )
322
+ if exclude_outcomes :
323
+ return norm_names (exclude_outcomes .split ("," ))
324
+
325
+ if not exclude_outcomes :
326
+ exclude_outcomes = config .getini (Option .MD_EXCLUDE_OUTCOMES .inioption_str )
327
+
328
+ if not exclude_outcomes :
329
+ return Default .EXCLUDE_RESULTS
330
+
331
+ if isinstance (exclude_outcomes , list ):
332
+ # list will be passed via pytest config file
333
+ return norm_names (exclude_outcomes )
334
+ elif isinstance (exclude_outcomes , str ):
335
+ # comma-separated string (e.g. passed,skipped) will be passed via the command line option
336
+ return norm_names (exclude_outcomes .split ("," ))
337
+
338
+ raise TypeError (f"Unexpected type { type (exclude_outcomes )} for exclude_outcomes" )
339
+
340
+
301
341
def retrieve_color_policy (config : Config ) -> ColorPolicy :
302
342
color_policy = config .option .md_report_color
303
343
@@ -417,11 +457,17 @@ def make_md_report(
417
457
color_policy : ColorPolicy ,
418
458
apply_ansi_escape : bool ,
419
459
md_flavor : MarkdownFlavor ,
460
+ exclude_outcomes : List [str ],
420
461
) -> str :
421
462
verbosity_level = retrieve_verbosity_level (config )
422
463
423
464
outcomes = ["passed" , "failed" , "error" , "skipped" , "xfailed" , "xpassed" ]
465
+ outcomes = [key for key in outcomes if key not in exclude_outcomes ]
424
466
outcomes = [key for key in outcomes if total_stats .get (key , 0 ) > 0 ]
467
+
468
+ if not outcomes :
469
+ return ""
470
+
425
471
results_per_testfunc = extract_pytest_stats (
426
472
reporter = reporter , outcomes = outcomes , verbosity_level = verbosity_level
427
473
)
@@ -505,6 +551,7 @@ def pytest_unconfigure(config: Config) -> None:
505
551
output_filepath = retrieve_output_filepath (config )
506
552
color_policy = retrieve_color_policy (config )
507
553
md_flavor = retrieve_md_flavor (config )
554
+ exclude_outcomes = retrieve_exclude_outcomes (config )
508
555
509
556
is_output_term = is_tee or not output_filepath
510
557
is_output_file = is_not_null_string (output_filepath )
@@ -522,6 +569,7 @@ def pytest_unconfigure(config: Config) -> None:
522
569
color_policy = term_color_policy ,
523
570
apply_ansi_escape = apply_ansi_escape_to_term ,
524
571
md_flavor = md_flavor ,
572
+ exclude_outcomes = exclude_outcomes ,
525
573
)
526
574
reporter ._tw .write (term_report )
527
575
@@ -544,6 +592,7 @@ def pytest_unconfigure(config: Config) -> None:
544
592
color_policy = file_color_policy ,
545
593
apply_ansi_escape = apply_ansi_escape_to_file ,
546
594
md_flavor = md_flavor ,
595
+ exclude_outcomes = exclude_outcomes ,
547
596
)
548
597
549
598
if file_report :
0 commit comments