summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrien Di Mascio <Adrien.DiMascio@logilab.fr>2007-04-17 17:14:02 +0200
committerAdrien Di Mascio <Adrien.DiMascio@logilab.fr>2007-04-17 17:14:02 +0200
commitad4456b25e584fc9a14275549d2dfba5564b081b (patch)
tree30c17b261ce607fd7636b9467e21fb3b71f7e941
parenta4a8ed0ab4104ce1cfcc278d39864f11f97ea045 (diff)
downloadlogilab-common-ad4456b25e584fc9a14275549d2dfba5564b081b.tar.gz
only store tracebacks in pdbmode
-rw-r--r--pytest.py22
-rw-r--r--testlib.py19
2 files changed, 25 insertions, 16 deletions
diff --git a/pytest.py b/pytest.py
index 5f34674..e2eecca 100644
--- a/pytest.py
+++ b/pytest.py
@@ -60,7 +60,6 @@ def autopath(projdir=os.getcwd()):
else:
sys.path.insert(0, curdir)
sys.path.insert(0, '')
- return curdir
class GlobalTestReport(object):
@@ -219,6 +218,7 @@ def parseargs():
def rebuild_cmdline(option, opt, value, parser):
"""carry the option to unittest_main"""
newargs.append(opt)
+
def rebuild_and_store(option, opt, value, parser):
"""carry the option to unittest_main and store
@@ -235,8 +235,9 @@ def parseargs():
# unittest_main options provided and passed through pytest
parser.add_option('-v', '--verbose', callback=rebuild_cmdline,
action="callback", help="Verbose output")
- parser.add_option('-i', '--pdb', callback=rebuild_cmdline,
- action="callback", help="Enable test failure inspection")
+ parser.add_option('-i', '--pdb', callback=rebuild_and_store,
+ dest="pdb", action="callback",
+ help="Enable test failure inspection (conflicts with --coverage)")
parser.add_option('-x', '--exitfirst', callback=rebuild_and_store,
dest="exitfirst",
action="callback", help="Exit on first failure "
@@ -268,10 +269,13 @@ def parseargs():
pass
else:
parser.add_option('--coverage', dest="coverage", default=False,
- action="store_true", help="run tests with pycoverage")
+ action="store_true",
+ help="run tests with pycoverage (conflicts with --pdb)")
# parse the command line
options, args = parser.parse_args()
+ if options.pdb and getattr(options, 'coverage', False):
+ parser.error("'pdb' and 'coverage' options are exclusive")
filenames = [arg for arg in args if arg.endswith('.py')]
if filenames:
if len(filenames) > 1:
@@ -293,7 +297,7 @@ def parseargs():
def run():
- rootdir = autopath()
+ autopath()
tester = PyTester()
options, newargs, explicitfile = parseargs()
# mock a new command line
@@ -312,7 +316,7 @@ def run():
else:
tester.testall(options.exitfirst)
finally:
- errcode = tester.
+ errcode = tester.show_report()
if covermode:
here = osp.abspath(os.getcwd())
if this_is_a_testdir(here):
@@ -322,8 +326,6 @@ def run():
print "computing code coverage (%s), this might thake some time" % \
morfdir
cvg.save()
- executed = [fname for fname in cvg.cexecuted if fname.startswith(morfdir)
- if osp.isfile(fname)]
- cvg.annotate(executed)
- cvg.report(executed, False)
+ cvg.annotate([morfdir])
+ cvg.report([morfdir], False)
sys.exit(errcode)
diff --git a/testlib.py b/testlib.py
index e849ae3..97c8902 100644
--- a/testlib.py
+++ b/testlib.py
@@ -316,7 +316,8 @@ from cStringIO import StringIO
class SkipAwareTestResult(unittest._TextTestResult):
def __init__(self, stream, descriptions, verbosity,
- exitfirst=False, capture=0, printonly=None):
+ exitfirst=False, capture=0, printonly=None,
+ pdbmode=False):
super(SkipAwareTestResult, self).__init__(stream,
descriptions, verbosity)
self.skipped = []
@@ -325,10 +326,12 @@ class SkipAwareTestResult(unittest._TextTestResult):
self.exitfirst = exitfirst
self.capture = capture
self.printonly = printonly
+ self.pdbmode = pdbmode
def _create_pdb(self, test_descr):
- self.debuggers.append(Debugger(sys.exc_info()[2]))
- self.descrs.append(test_descr)
+ if self.pdbmode:
+ self.debuggers.append(Debugger(sys.exc_info()[2]))
+ self.descrs.append(test_descr)
def addError(self, test, err):
exc_type, exc, tcbk = err
@@ -393,16 +396,19 @@ class SkipAwareTestResult(unittest._TextTestResult):
class SkipAwareTextTestRunner(unittest.TextTestRunner):
def __init__(self, stream=sys.stderr, verbosity=1,
- exitfirst=False, capture=False, printonly=None):
+ exitfirst=False, capture=False, printonly=None,
+ pdbmode=False):
super(SkipAwareTextTestRunner, self).__init__(stream=stream,
verbosity=verbosity)
self.exitfirst = exitfirst
self.capture = capture
self.printonly = printonly
+ self.pdbmode = pdbmode
def _makeResult(self):
return SkipAwareTestResult(self.stream, self.descriptions, self.verbosity,
- self.exitfirst, self.capture, self.printonly)
+ self.exitfirst, self.capture, self.printonly,
+ self.pdbmode)
class keywords(dict):
@@ -626,7 +632,8 @@ Examples:
self.testRunner = SkipAwareTextTestRunner(verbosity=self.verbosity,
exitfirst=self.exitfirst,
capture=self.capture,
- printonly=self.printonly)
+ printonly=self.printonly,
+ pdbmode=self.pdbmode)
result = self.testRunner.run(self.test)
if os.environ.get('PYDEBUG'):
warn("PYDEBUG usage is deprecated, use -i / --pdb instead", DeprecationWarning)