4444
4545
4646def pytest_addoption (parser : Parser ) -> None :
47- group = parser .getgroup ("subtests" )
48- group .addoption (
49- "--no-subtests-shortletter" ,
50- action = "store_true" ,
51- dest = "no_subtests_shortletter" ,
52- default = False ,
53- help = "Disables subtest output 'dots' in non-verbose mode (EXPERIMENTAL)" ,
54- )
55- group .addoption (
56- "--no-subtests-reports" ,
57- action = "store_true" ,
58- dest = "no_subtests_reports" ,
59- default = False ,
60- help = "Disables subtest output unless it's a failed subtest (EXPERIMENTAL)" ,
47+ Config ._add_verbosity_ini (
48+ parser ,
49+ Config .VERBOSITY_SUBTESTS ,
50+ help = (
51+ "Specify verbosity level for subtests. "
52+ "Higher levels will generate output for passed subtests. Failed subtests are always reported."
53+ ),
6154 )
6255
6356
@@ -372,14 +365,14 @@ def pytest_report_teststatus(
372365 if report .when != "call" :
373366 return None
374367
368+ quiet = config .get_verbosity (Config .VERBOSITY_SUBTESTS ) == 0
375369 if isinstance (report , SubtestReport ):
376370 outcome = report .outcome
377371 description = report ._sub_test_description ()
378- no_output = ("" , "" , "" )
379372
380373 if hasattr (report , "wasxfail" ):
381- if config . option . no_subtests_reports and outcome != "skipped" :
382- return no_output
374+ if quiet :
375+ return "" , "" , ""
383376 elif outcome == "skipped" :
384377 category = "xfailed"
385378 short = "y" # x letter is used for regular xfail, y for subtest xfail
@@ -394,26 +387,28 @@ def pytest_report_teststatus(
394387 # passed in case of xfail.
395388 # Let's pass this report to the next hook.
396389 return None
397- short = "" if config .option .no_subtests_shortletter else short
398- return f"subtests { category } " , short , f"{ description } { status } "
399-
400- if config .option .no_subtests_reports and outcome != "failed" :
401- return no_output
402- elif report .passed :
403- short = "" if config .option .no_subtests_shortletter else ","
404- return f"subtests { outcome } " , short , f"{ description } SUBPASSED"
405- elif report .skipped :
406- short = "" if config .option .no_subtests_shortletter else "-"
407- return outcome , short , f"{ description } SUBSKIPPED"
408- elif outcome == "failed" :
409- short = "" if config .option .no_subtests_shortletter else "u"
410- return outcome , short , f"{ description } SUBFAILED"
390+ return category , short , f"{ status } { description } "
391+
392+ if report .failed :
393+ return outcome , "u" , f"SUBFAILED{ description } "
394+ else :
395+ if report .passed :
396+ if quiet :
397+ return "" , "" , ""
398+ else :
399+ return f"subtests { outcome } " , "u" , f"SUBPASSED{ description } "
400+ elif report .skipped :
401+ if quiet :
402+ return "" , "" , ""
403+ else :
404+ return outcome , "-" , f"SUBSKIPPED{ description } "
405+
411406 else :
412407 failed_subtests_count = config .stash [failed_subtests_key ][report .nodeid ]
413- # Top-level test, fail it it contains failed subtests and it has passed.
408+ # Top-level test, fail if it contains failed subtests and it has passed.
414409 if report .passed and failed_subtests_count > 0 :
415410 report .outcome = "failed"
416411 suffix = "s" if failed_subtests_count > 1 else ""
417- report .longrepr = f"Contains { failed_subtests_count } failed subtest{ suffix } "
412+ report .longrepr = f"contains { failed_subtests_count } failed subtest{ suffix } "
418413
419414 return None
0 commit comments