@@ -2773,7 +2773,11 @@ def __init__(self, **kwargs):
27732773
27742774 class config :
27752775 def __init__ (self ):
2776- self .option = Namespace (verbose = 0 )
2776+ self .option = Namespace (verbose = 0 , force_short_summary = False )
2777+
2778+ def get_verbosity (self , verbosity_type = None ):
2779+ assert verbosity_type == Config .VERBOSITY_ASSERTIONS
2780+ return self .option .verbose
27772781
27782782 class rep :
27792783 def _get_verbose_word_with_markup (self , * args ):
@@ -2865,6 +2869,15 @@ def test():
28652869 ],
28662870 )
28672871
2872+ # -v also keeps the current truncated behavior.
2873+ result = pytester .runpytest ("-v" )
2874+ result .stdout .fnmatch_lines (
2875+ [
2876+ "*short test summary info*" ,
2877+ "* assert 'AAA..." ,
2878+ ],
2879+ )
2880+
28682881 # No truncation with -vv.
28692882 result = pytester .runpytest ("-vv" )
28702883 result .stdout .fnmatch_lines (
@@ -2904,8 +2917,60 @@ def test_len_dict():
29042917 )
29052918
29062919
2907- def test_force_short_summary (monkeypatch : MonkeyPatch , pytester : Pytester ) -> None :
2920+ @pytest .mark .parametrize ("use_ci" , [False , True ])
2921+ def test_short_summary_on_ci (monkeypatch : MonkeyPatch , pytester : Pytester , use_ci : bool ) -> None :
2922+ monkeypatch .setattr (_pytest .terminal , "running_on_ci" , lambda : use_ci )
2923+
2924+ pytester .makepyfile ("def test(): assert 0, 'this_failed' * 100" )
2925+
2926+ result = pytester .runpytest ()
2927+ assert result .ret == 1
2928+ result .stdout .fnmatch_lines (
2929+ [
2930+ "*short test summary info*" ,
2931+ "*AssertionError: " + "this_failed" * 100 ,
2932+ ]
2933+ if use_ci
2934+ else ["*short test summary info*" , "*AssertionError: this_failedthis_fa..." ]
2935+ )
2936+
2937+
2938+ def test_short_summary_assertion_verbosity (monkeypatch : MonkeyPatch , pytester : Pytester ) -> None :
29082939 monkeypatch .setattr (_pytest .terminal , "running_on_ci" , lambda : False )
2940+ config_file = pytester .makeini ("[pytest]\n verbosity_assertions = 2" )
2941+ pytester .makepyfile ("def test(): assert 'A' * 200 == 'B' * 200" )
2942+
2943+ result = pytester .runpytest ("-c" , str (config_file ))
2944+ assert result .ret == 1
2945+ result .stdout .fnmatch_lines (
2946+ [
2947+ "*short test summary info*" ,
2948+ "*assert 'AAAAA* == 'BBBBB*" ,
2949+ ]
2950+ )
2951+
2952+
2953+ @pytest .mark .parametrize (
2954+ ("use_ci" , "pytest_args" , "ini_options" ),
2955+ [
2956+ pytest .param (True , (), None , id = "ci" ),
2957+ pytest .param (False , ("-vv" ,), None , id = "vv" ),
2958+ pytest .param (
2959+ False ,
2960+ (),
2961+ "[pytest]\n verbosity_assertions = 2" ,
2962+ id = "verbosity_assertions" ,
2963+ ),
2964+ ],
2965+ )
2966+ def test_force_short_summary (
2967+ monkeypatch : MonkeyPatch ,
2968+ pytester : Pytester ,
2969+ use_ci : bool ,
2970+ pytest_args : tuple [str , ...],
2971+ ini_options : str | None ,
2972+ ) -> None :
2973+ monkeypatch .setattr (_pytest .terminal , "running_on_ci" , lambda : use_ci )
29092974
29102975 pytester .makepyfile (
29112976 """
@@ -2914,7 +2979,12 @@ def test():
29142979 """
29152980 )
29162981
2917- result = pytester .runpytest ("-vv" , "--force-short-summary" )
2982+ args = (* pytest_args , "--force-short-summary" )
2983+ if ini_options is not None :
2984+ config_file = pytester .makeini (ini_options )
2985+ args = ("-c" , str (config_file ), * args )
2986+
2987+ result = pytester .runpytest (* args )
29182988 assert result .ret == 1
29192989 result .stdout .fnmatch_lines (
29202990 ["*short test summary info*" , "*AssertionError: assert 'a\\ na\\ na\\ na..." ]
0 commit comments