File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -90,6 +90,7 @@ Markus Unterwaditzer
9090Martijn Faassen
9191Martin K. Scherer
9292Martin Prusse
93+ Mathieu Clabaut
9394Matt Bachmann
9495Matt Williams
9596Matthias Hafner
Original file line number Diff line number Diff line change 1717 or implicitly as a plugin (`#2005 `_).
1818 Thanks `@RonnyPfannschmidt `_ for the report and `@nicoddemus `_ for the PR.
1919
20- *
20+ * Report teardown output on test failure (`#442 `_).
21+ Thanks `@matclab `_ or the PR.
2122
2223*
2324
2627
2728.. _@cwitty : https://github.com/cwitty
2829.. _@okulynyak : https://github.com/okulynyak
30+ .. _@matclab : https://github.com/matclab
2931
32+ .. _#442 : https://github.com/pytest-dev/pytest/issues/442
3033.. _#1976 : https://github.com/pytest-dev/pytest/issues/1976
3134.. _#1998 : https://github.com/pytest-dev/pytest/issues/1998
3235.. _#2004 : https://github.com/pytest-dev/pytest/issues/2004
Original file line number Diff line number Diff line change @@ -458,6 +458,15 @@ def summary_passes(self):
458458 self .write_sep ("_" , msg )
459459 self ._outrep_summary (rep )
460460
461+ def print_teardown_sections (self , rep ):
462+ for secname , content in rep .sections :
463+ if 'teardown' in secname :
464+ self ._tw .sep ('-' , secname )
465+ if content [- 1 :] == "\n " :
466+ content = content [:- 1 ]
467+ self ._tw .line (content )
468+
469+
461470 def summary_failures (self ):
462471 if self .config .option .tbstyle != "no" :
463472 reports = self .getreports ('failed' )
@@ -473,6 +482,9 @@ def summary_failures(self):
473482 markup = {'red' : True , 'bold' : True }
474483 self .write_sep ("_" , msg , ** markup )
475484 self ._outrep_summary (rep )
485+ for report in self .getreports ('' ):
486+ if report .nodeid == rep .nodeid and report .when == 'teardown' :
487+ self .print_teardown_sections (report )
476488
477489 def summary_errors (self ):
478490 if self .config .option .tbstyle != "no" :
Original file line number Diff line number Diff line change @@ -370,6 +370,31 @@ def teardown_function(function):
370370 "*1 failed*1 error*" ,
371371 ])
372372
373+ def test_setup_teardown_output_and_test_failure (self , testdir ):
374+ """ Test for issue #442 """
375+ testdir .makepyfile ("""
376+ def setup_function(function):
377+ print ("setup func")
378+
379+ def test_fail():
380+ assert 0, "failingfunc"
381+
382+ def teardown_function(function):
383+ print ("teardown func")
384+ """ )
385+ result = testdir .runpytest ()
386+ result .stdout .fnmatch_lines ([
387+ "*test_fail*" ,
388+ "*def test_fail():" ,
389+ "*failingfunc*" ,
390+ "*Captured stdout setup*" ,
391+ "*setup func*" ,
392+ "*Captured stdout teardown*" ,
393+ "*teardown func*" ,
394+
395+ "*1 failed*" ,
396+ ])
397+
373398class TestTerminalFunctional :
374399 def test_deselected (self , testdir ):
375400 testpath = testdir .makepyfile ("""
You can’t perform that action at this time.
0 commit comments