@@ -678,6 +678,7 @@ def pytest_terminal_summary(self):
678
678
self .summary_failures ()
679
679
self .summary_warnings ()
680
680
yield
681
+ self .short_test_summary ()
681
682
self .summary_passes ()
682
683
# Display any extra warnings from teardown here (if any).
683
684
self .summary_warnings ()
@@ -873,58 +874,100 @@ def summary_stats(self):
873
874
if self .verbosity == - 1 :
874
875
self .write_line (msg , ** markup )
875
876
877
+ def short_test_summary (self ):
878
+ if not self .reportchars :
879
+ return
876
880
877
- def pytest_terminal_summary (terminalreporter ):
878
- tr = terminalreporter
879
- if not tr .reportchars :
880
- return
881
-
882
- lines = []
883
- for char in tr .reportchars :
884
- action = REPORTCHAR_ACTIONS .get (char , lambda tr , lines : None )
885
- action (terminalreporter , lines )
886
-
887
- if lines :
888
- tr ._tw .sep ("=" , "short test summary info" )
889
- for line in lines :
890
- tr ._tw .line (line )
891
-
892
-
893
- def show_simple (terminalreporter , lines , stat ):
894
- failed = terminalreporter .stats .get (stat )
895
- if failed :
896
- config = terminalreporter .config
897
- for rep in failed :
898
- verbose_word = _get_report_str (config , rep )
899
- pos = _get_pos (config , rep )
900
- lines .append ("%s %s" % (verbose_word , pos ))
901
-
902
-
903
- def show_xfailed (terminalreporter , lines ):
904
- xfailed = terminalreporter .stats .get ("xfailed" )
905
- if xfailed :
906
- config = terminalreporter .config
907
- for rep in xfailed :
908
- verbose_word = _get_report_str (config , rep )
909
- pos = _get_pos (config , rep )
910
- lines .append ("%s %s" % (verbose_word , pos ))
911
- reason = rep .wasxfail
912
- if reason :
913
- lines .append (" " + str (reason ))
914
-
915
-
916
- def show_xpassed (terminalreporter , lines ):
917
- xpassed = terminalreporter .stats .get ("xpassed" )
918
- if xpassed :
919
- config = terminalreporter .config
920
- for rep in xpassed :
921
- verbose_word = _get_report_str (config , rep )
922
- pos = _get_pos (config , rep )
923
- reason = rep .wasxfail
924
- lines .append ("%s %s %s" % (verbose_word , pos , reason ))
925
-
926
-
927
- def folded_skips (skipped ):
881
+ def show_simple (lines , stat ):
882
+ failed = self .stats .get (stat )
883
+ if failed :
884
+ config = self .config
885
+ for rep in failed :
886
+ verbose_word = _get_report_str (config , rep )
887
+ pos = _get_pos (config , rep )
888
+ lines .append ("%s %s" % (verbose_word , pos ))
889
+
890
+ def show_xfailed (lines ):
891
+ xfailed = self .stats .get ("xfailed" )
892
+ if xfailed :
893
+ config = self .config
894
+ for rep in xfailed :
895
+ verbose_word = _get_report_str (config , rep )
896
+ pos = _get_pos (config , rep )
897
+ lines .append ("%s %s" % (verbose_word , pos ))
898
+ reason = rep .wasxfail
899
+ if reason :
900
+ lines .append (" " + str (reason ))
901
+
902
+ def show_xpassed (lines ):
903
+ xpassed = self .stats .get ("xpassed" )
904
+ if xpassed :
905
+ config = self .config
906
+ for rep in xpassed :
907
+ verbose_word = _get_report_str (config , rep )
908
+ pos = _get_pos (config , rep )
909
+ reason = rep .wasxfail
910
+ lines .append ("%s %s %s" % (verbose_word , pos , reason ))
911
+
912
+ def show_skipped (lines ):
913
+ skipped = self .stats .get ("skipped" , [])
914
+ if skipped :
915
+ fskips = _folded_skips (skipped )
916
+ if fskips :
917
+ verbose_word = _get_report_str (self .config , report = skipped [0 ])
918
+ for num , fspath , lineno , reason in fskips :
919
+ if reason .startswith ("Skipped: " ):
920
+ reason = reason [9 :]
921
+ if lineno is not None :
922
+ lines .append (
923
+ "%s [%d] %s:%d: %s"
924
+ % (verbose_word , num , fspath , lineno + 1 , reason )
925
+ )
926
+ else :
927
+ lines .append (
928
+ "%s [%d] %s: %s" % (verbose_word , num , fspath , reason )
929
+ )
930
+
931
+ def shower (stat ):
932
+ def show_ (lines ):
933
+ return show_simple (lines , stat )
934
+
935
+ return show_
936
+
937
+ def _get_report_str (config , report ):
938
+ _category , _short , verbose = config .hook .pytest_report_teststatus (
939
+ report = report , config = config
940
+ )
941
+ return verbose
942
+
943
+ def _get_pos (config , rep ):
944
+ nodeid = config .cwd_relative_nodeid (rep .nodeid )
945
+ return nodeid
946
+
947
+ REPORTCHAR_ACTIONS = {
948
+ "x" : show_xfailed ,
949
+ "X" : show_xpassed ,
950
+ "f" : shower ("failed" ),
951
+ "F" : shower ("failed" ),
952
+ "s" : show_skipped ,
953
+ "S" : show_skipped ,
954
+ "p" : shower ("passed" ),
955
+ "E" : shower ("error" ),
956
+ }
957
+
958
+ lines = []
959
+ for char in self .reportchars :
960
+ action = REPORTCHAR_ACTIONS .get (char )
961
+ if action : # skipping e.g. "P" (passed with output) here.
962
+ action (lines )
963
+
964
+ if lines :
965
+ self .write_sep ("=" , "short test summary info" )
966
+ for line in lines :
967
+ self .write_line (line )
968
+
969
+
970
+ def _folded_skips (skipped ):
928
971
d = {}
929
972
for event in skipped :
930
973
key = event .longrepr
@@ -946,56 +989,6 @@ def folded_skips(skipped):
946
989
return values
947
990
948
991
949
- def show_skipped (terminalreporter , lines ):
950
- tr = terminalreporter
951
- skipped = tr .stats .get ("skipped" , [])
952
- if skipped :
953
- fskips = folded_skips (skipped )
954
- if fskips :
955
- verbose_word = _get_report_str (terminalreporter .config , report = skipped [0 ])
956
- for num , fspath , lineno , reason in fskips :
957
- if reason .startswith ("Skipped: " ):
958
- reason = reason [9 :]
959
- if lineno is not None :
960
- lines .append (
961
- "%s [%d] %s:%d: %s"
962
- % (verbose_word , num , fspath , lineno + 1 , reason )
963
- )
964
- else :
965
- lines .append ("%s [%d] %s: %s" % (verbose_word , num , fspath , reason ))
966
-
967
-
968
- def shower (stat ):
969
- def show_ (terminalreporter , lines ):
970
- return show_simple (terminalreporter , lines , stat )
971
-
972
- return show_
973
-
974
-
975
- def _get_report_str (config , report ):
976
- _category , _short , verbose = config .hook .pytest_report_teststatus (
977
- report = report , config = config
978
- )
979
- return verbose
980
-
981
-
982
- def _get_pos (config , rep ):
983
- nodeid = config .cwd_relative_nodeid (rep .nodeid )
984
- return nodeid
985
-
986
-
987
- REPORTCHAR_ACTIONS = {
988
- "x" : show_xfailed ,
989
- "X" : show_xpassed ,
990
- "f" : shower ("failed" ),
991
- "F" : shower ("failed" ),
992
- "s" : show_skipped ,
993
- "S" : show_skipped ,
994
- "p" : shower ("passed" ),
995
- "E" : shower ("error" ),
996
- }
997
-
998
-
999
992
def build_summary_stats_line (stats ):
1000
993
known_types = (
1001
994
"failed passed skipped deselected xfailed xpassed warnings error" .split ()
0 commit comments