@@ -725,18 +725,22 @@ def pytest_terminal_summary_main(tr, id):
725
725
orig_tbstyle = config .option .tbstyle
726
726
orig_reportchars = tr .reportchars
727
727
728
- report_files = dict (
729
- durations = "durations" ,
730
- short_summary = "short_summary" ,
731
- summary_errors = "errors" ,
732
- summary_failures = "failures" ,
733
- summary_warnings = "warnings" ,
734
- summary_passes = "passes" ,
735
- summary_stats = "stats" ,
736
- )
737
728
dir = "reports"
738
729
Path (dir ).mkdir (parents = True , exist_ok = True )
739
- report_files .update ((k , f"{ dir } /report_{ id } _{ v } .txt" ) for k , v in report_files .items ())
730
+ report_files = {
731
+ k : f"{ dir } /report_{ id } _{ k } .txt"
732
+ for k in [
733
+ "durations" ,
734
+ "errors" ,
735
+ "failures_long" ,
736
+ "failures_short" ,
737
+ "failures_line" ,
738
+ "passes" ,
739
+ "stats" ,
740
+ "summary_short" ,
741
+ "warnings" ,
742
+ ]
743
+ }
740
744
741
745
# custom durations report
742
746
# note: there is no need to call pytest --durations=XX to get this separate report
@@ -757,34 +761,60 @@ def pytest_terminal_summary_main(tr, id):
757
761
break
758
762
f .write (f"{ rep .duration :02.2f} s { rep .when :<8} { rep .nodeid } \n " )
759
763
764
+ def summary_failures_short (tr ):
765
+ # expecting that the reports were --tb=long (default) so we chop them off here to the last frame
766
+ reports = tr .getreports ("failed" )
767
+ if not reports :
768
+ return
769
+ tr .write_sep ("=" , "FAILURES SHORT STACK" )
770
+ for rep in reports :
771
+ msg = tr ._getfailureheadline (rep )
772
+ tr .write_sep ("_" , msg , red = True , bold = True )
773
+ # chop off the optional leading extra frames, leaving only the last one
774
+ longrepr = re .sub (r".*_ _ _ (_ ){10,}_ _ " , "" , rep .longreprtext , 0 , re .M | re .S )
775
+ tr ._tw .line (longrepr )
776
+ # note: not printing out any rep.sections to keep the report short
777
+
760
778
# use ready-made report funcs, we are just hijacking the filehandle to log to a dedicated file each
761
779
# adapted from https://github.com/pytest-dev/pytest/blob/897f151e/src/_pytest/terminal.py#L814
762
780
# note: some pytest plugins may interfere by hijacking the default `terminalreporter` (e.g.
763
781
# pytest-instafail does that)
764
- tr .reportchars = "wPpsxXEf" # emulate -rA (used in summary_passes() and short_test_summary())
765
- config .option .tbstyle = "auto"
766
- with open (report_files ["summary_failures" ], "w" ) as f :
782
+
783
+ # report failures with line/short/long styles
784
+ config .option .tbstyle = "auto" # full tb
785
+ with open (report_files ["failures_long" ], "w" ) as f :
786
+ tr ._tw = create_terminal_writer (config , f )
787
+ tr .summary_failures ()
788
+
789
+ # config.option.tbstyle = "short" # short tb
790
+ with open (report_files ["failures_short" ], "w" ) as f :
791
+ tr ._tw = create_terminal_writer (config , f )
792
+ summary_failures_short (tr )
793
+
794
+ config .option .tbstyle = "line" # one line per error
795
+ with open (report_files ["failures_line" ], "w" ) as f :
767
796
tr ._tw = create_terminal_writer (config , f )
768
797
tr .summary_failures ()
769
798
770
- with open (report_files ["summary_errors " ], "w" ) as f :
799
+ with open (report_files ["errors " ], "w" ) as f :
771
800
tr ._tw = create_terminal_writer (config , f )
772
801
tr .summary_errors ()
773
802
774
- with open (report_files ["summary_warnings " ], "w" ) as f :
803
+ with open (report_files ["warnings " ], "w" ) as f :
775
804
tr ._tw = create_terminal_writer (config , f )
776
805
tr .summary_warnings () # normal warnings
777
806
tr .summary_warnings () # final warnings
778
807
779
- with open (report_files ["summary_passes" ], "w" ) as f :
808
+ tr .reportchars = "wPpsxXEf" # emulate -rA (used in summary_passes() and short_test_summary())
809
+ with open (report_files ["passes" ], "w" ) as f :
780
810
tr ._tw = create_terminal_writer (config , f )
781
811
tr .summary_passes ()
782
812
783
- with open (report_files ["short_summary " ], "w" ) as f :
813
+ with open (report_files ["summary_short " ], "w" ) as f :
784
814
tr ._tw = create_terminal_writer (config , f )
785
815
tr .short_test_summary ()
786
816
787
- with open (report_files ["summary_stats " ], "w" ) as f :
817
+ with open (report_files ["stats " ], "w" ) as f :
788
818
tr ._tw = create_terminal_writer (config , f )
789
819
tr .summary_stats ()
790
820
0 commit comments