fix #128 show tracebacks for all failures and errors that haven't beed PDB-debugged
This commit is contained in:
		
							parent
							
								
									695bffc83d
								
							
						
					
					
						commit
						4fa7a2e8ce
					
				| 
						 | 
				
			
			@ -13,6 +13,7 @@ Changes between 1.3.4 and 2.0.0dev0
 | 
			
		|||
  is removed).
 | 
			
		||||
- add a new "-q" option which decreases verbosity and prints a more
 | 
			
		||||
  nose/unittest-style "dot" output.
 | 
			
		||||
- fix issue135 - marks now work with unittest test cases as well
 | 
			
		||||
- fix issue126 - introduce py.test.set_trace() to trace execution via
 | 
			
		||||
  PDB during the running of tests even if capturing is ongoing.
 | 
			
		||||
- fix issue123 - new "python -m py.test" invocation for py.test
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -42,10 +42,6 @@ def pytest_runtest_makereport():
 | 
			
		|||
    pytestPDB.item = None
 | 
			
		||||
    
 | 
			
		||||
class PdbInvoke:
 | 
			
		||||
    def pytest_sessionfinish(self, session):
 | 
			
		||||
        # don't display failures again at the end
 | 
			
		||||
        session.config.option.tbstyle = "no"
 | 
			
		||||
 | 
			
		||||
    @pytest.mark.tryfirst
 | 
			
		||||
    def pytest_runtest_makereport(self, item, call, __multicall__):
 | 
			
		||||
        if not call.excinfo or \
 | 
			
		||||
| 
						 | 
				
			
			@ -62,6 +58,7 @@ class PdbInvoke:
 | 
			
		|||
        rep.toterminal(tw)
 | 
			
		||||
        tw.sep(">", "entering PDB")
 | 
			
		||||
        post_mortem(call.excinfo._excinfo[2])
 | 
			
		||||
        rep._pdbshown = True
 | 
			
		||||
        return rep
 | 
			
		||||
 | 
			
		||||
def post_mortem(t):
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -358,7 +358,9 @@ def skip(msg=""):
 | 
			
		|||
skip.Exception = Skipped
 | 
			
		||||
 | 
			
		||||
def fail(msg="", pytrace=True):
 | 
			
		||||
    """ explicitely fail an currently-executing test with the given Message. """
 | 
			
		||||
    """ explicitely fail an currently-executing test with the given Message.
 | 
			
		||||
    if @pytrace is not True the msg represents the full failure information.
 | 
			
		||||
    """
 | 
			
		||||
    __tracebackhide__ = True
 | 
			
		||||
    raise Failed(msg=msg, pytrace=pytrace)
 | 
			
		||||
fail.Exception = Failed
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -332,13 +332,21 @@ class TerminalReporter:
 | 
			
		|||
    #
 | 
			
		||||
    # summaries for sessionfinish
 | 
			
		||||
    #
 | 
			
		||||
    def getreports(self, name):
 | 
			
		||||
        l = []
 | 
			
		||||
        for x in self.stats.get(name, []):
 | 
			
		||||
            if not hasattr(x, '_pdbshown'):
 | 
			
		||||
                l.append(x)
 | 
			
		||||
        return l
 | 
			
		||||
 | 
			
		||||
    def summary_failures(self):
 | 
			
		||||
        tbstyle = self.config.option.tbstyle
 | 
			
		||||
        if 'failed' in self.stats and tbstyle != "no":
 | 
			
		||||
        if self.config.option.tbstyle != "no":
 | 
			
		||||
            reports = self.getreports('failed')
 | 
			
		||||
            if not reports:
 | 
			
		||||
                return
 | 
			
		||||
            self.write_sep("=", "FAILURES")
 | 
			
		||||
            for rep in self.stats['failed']:
 | 
			
		||||
                if tbstyle == "line":
 | 
			
		||||
            for rep in reports:
 | 
			
		||||
                if self.config.option.tbstyle == "line":
 | 
			
		||||
                    line = self._getcrashline(rep)
 | 
			
		||||
                    self.write_line(line)
 | 
			
		||||
                else:
 | 
			
		||||
| 
						 | 
				
			
			@ -347,7 +355,10 @@ class TerminalReporter:
 | 
			
		|||
                    rep.toterminal(self._tw)
 | 
			
		||||
 | 
			
		||||
    def summary_errors(self):
 | 
			
		||||
        if 'error' in self.stats and self.config.option.tbstyle != "no":
 | 
			
		||||
        if self.config.option.tbstyle != "no":
 | 
			
		||||
            reports = self.getreports('error')
 | 
			
		||||
            if not reports:
 | 
			
		||||
                return
 | 
			
		||||
            self.write_sep("=", "ERRORS")
 | 
			
		||||
            for rep in self.stats['error']:
 | 
			
		||||
                msg = self._getfailureheadline(rep)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -5,7 +5,7 @@ see http://pytest.org for documentation and details
 | 
			
		|||
 | 
			
		||||
(c) Holger Krekel and others, 2004-2010
 | 
			
		||||
"""
 | 
			
		||||
__version__ = '2.0.0.dev32'
 | 
			
		||||
__version__ = '2.0.0.dev33'
 | 
			
		||||
__all__ = ['main']
 | 
			
		||||
 | 
			
		||||
from _pytest.core import main, UsageError, _preloadplugins
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										2
									
								
								setup.py
								
								
								
								
							
							
						
						
									
										2
									
								
								setup.py
								
								
								
								
							| 
						 | 
				
			
			@ -22,7 +22,7 @@ def main():
 | 
			
		|||
        name='pytest',
 | 
			
		||||
        description='py.test: simple powerful testing with Python',
 | 
			
		||||
        long_description = long_description,
 | 
			
		||||
        version='2.0.0.dev32',
 | 
			
		||||
        version='2.0.0.dev33',
 | 
			
		||||
        url='http://pytest.org',
 | 
			
		||||
        license='MIT license',
 | 
			
		||||
        platforms=['unix', 'linux', 'osx', 'cygwin', 'win32'],
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -143,3 +143,11 @@ class TestPDB:
 | 
			
		|||
        child.expect("x = 5")
 | 
			
		||||
        child.sendeof()
 | 
			
		||||
        child.wait()
 | 
			
		||||
 | 
			
		||||
    def test_pdb_collection_failure_is_shown(self, testdir):
 | 
			
		||||
        p1 = testdir.makepyfile("""xxx """)
 | 
			
		||||
        result = testdir.runpytest("--pdb", p1)
 | 
			
		||||
        result.stdout.fnmatch_lines([
 | 
			
		||||
            "*NameError*xxx*",
 | 
			
		||||
            "*1 error*",
 | 
			
		||||
        ])
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue