diff options
author | Marius Gedminas <marius@gedmin.as> | 2013-02-07 23:04:46 +0000 |
---|---|---|
committer | Marius Gedminas <marius@gedmin.as> | 2013-02-07 23:04:46 +0000 |
commit | 03e77bf187ecbbb53d9e853fcbe16612ef1ca5e0 (patch) | |
tree | 5492f7fe8b798016e231125c423fde4dce39ecb1 /src | |
parent | 5a72bca56916f5d8f209ae9ba1e55a3c5cfeaab4 (diff) | |
download | zope-tal-03e77bf187ecbbb53d9e853fcbe16612ef1ca5e0.tar.gz |
Better test failure reporting in FileTestCase
Previously the diff would be printed to stdout in the middle of a sea of
dots, and *then* you'd get test failure assertions mentioning only the
filename (and on Python 3.3 you'd also get a gratuitous SystemExit
traceback in addition to the assertion failure)
Now you get a sane single assertion failure with the diff inside it.
Diffstat (limited to 'src')
-rw-r--r-- | src/zope/tal/runtest.py | 5 | ||||
-rw-r--r-- | src/zope/tal/tests/test_files.py | 28 |
2 files changed, 22 insertions, 11 deletions
diff --git a/src/zope/tal/runtest.py b/src/zope/tal/runtest.py index 3677902..5c50e52 100644 --- a/src/zope/tal/runtest.py +++ b/src/zope/tal/runtest.py @@ -126,7 +126,10 @@ def main(): if not quiet and expected is not None: showdiff(expected, actual) if errors: - sys.exit(1) + if unittesting: + return 1 + else: + sys.exit(1) def readlines(f): L = [] diff --git a/src/zope/tal/tests/test_files.py b/src/zope/tal/tests/test_files.py index eff23ee..858c8aa 100644 --- a/src/zope/tal/tests/test_files.py +++ b/src/zope/tal/tests/test_files.py @@ -19,6 +19,13 @@ import os import sys import unittest +try: + # Python 2.x + from cStringIO import StringIO +except ImportError: + # Python 3.x + from io import StringIO + import zope.tal.runtest from zope.tal.tests import utils @@ -38,8 +45,6 @@ class FileTestCase(unittest.TestCase): def runTest(self): basename = os.path.basename(self.__file) - #sys.stdout.write(basename + " ") - sys.stdout.flush() if basename.startswith('test_sa'): sys.argv = ["", "-Q", "-a", self.__file] elif basename.startswith('test_metal'): @@ -48,14 +53,17 @@ class FileTestCase(unittest.TestCase): sys.argv = ["", "-Q", self.__file] pwd = os.getcwd() try: - try: - os.chdir(self.__dir) - zope.tal.runtest.main() - finally: - os.chdir(pwd) - except SystemExit as what: - if what.code: - self.fail("output for %s didn't match" % self.__file) + os.chdir(self.__dir) + old_stdout = sys.stdout + sys.stdout = StringIO() + failed = zope.tal.runtest.main() + finally: + captured_stdout = sys.stdout.getvalue() + sys.stdout = old_stdout + os.chdir(pwd) + if failed: + self.fail("output for %s didn't match:\n%s" + % (self.__file, captured_stdout)) try: script = __file__ |