chiark / gitweb /
More graceful handling of test failure; the exception is now reported
authorRichard Kettlewell <rjk@greenend.org.uk>
Sat, 23 May 2009 08:48:51 +0000 (09:48 +0100)
committerRichard Kettlewell <rjk@greenend.org.uk>
Sat, 23 May 2009 08:48:51 +0000 (09:48 +0100)
before the daemon is stopped, making it clearer where the failure was.

Add tests/fail.py, a test that always fails.  Naturally this is not
normally run, it's only there to test failure cleanup!

tests/Makefile.am
tests/dtest.py
tests/fail.py [new file with mode: 0755]

index 060d8507b50c39fa94d89605f3e51ca681ffe06f..dfe742488bf67c7f225cfe244b35ea884e61358a 100644 (file)
@@ -33,5 +33,5 @@ TESTS_ENVIRONMENT=${PYTHON} -u
 clean-local:
        rm -rf testroot *.log *.pyc
 
 clean-local:
        rm -rf testroot *.log *.pyc
 
-EXTRA_DIST=dtest.py ${TESTS}
+EXTRA_DIST=dtest.py ${TESTS} fail.py
 CLEANFILES=*.gcda *.gcov *.gcno *.c.html index.html
 CLEANFILES=*.gcda *.gcov *.gcno *.c.html index.html
index 38eadf8e3f4a2bff3bd7f76c9d601f2598ec5e2e..dd3c3a2d8a22c2fe5b034b2f9c3fe972735ddbbd 100644 (file)
@@ -1,7 +1,7 @@
 #-*-python-*-
 #
 # This file is part of DisOrder.
 #-*-python-*-
 #
 # This file is part of DisOrder.
-# Copyright (C) 2007, 2008 Richard Kettlewell
+# Copyright (C) 2007-2009 Richard Kettlewell
 #
 # This program is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
 #
 # This program is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -19,7 +19,7 @@
 
 """Utility module used by tests"""
 
 
 """Utility module used by tests"""
 
-import os,os.path,subprocess,sys,re,time,unicodedata,random,socket
+import os,os.path,subprocess,sys,re,time,unicodedata,random,socket,traceback
 
 def fatal(s):
     """Write an error message and exit"""
 
 def fatal(s):
     """Write an error message and exit"""
@@ -302,7 +302,7 @@ def run(module=None, report=True):
 
     Run the test in MODULE.  This can be a string (in which case the module
     will be imported) or a module object."""
 
     Run the test in MODULE.  This can be a string (in which case the module
     will be imported) or a module object."""
-    global tests
+    global tests, failures
     tests += 1
     # Locate the test module
     if module is None:
     tests += 1
     # Locate the test module
     if module is None:
@@ -333,8 +333,10 @@ def run(module=None, report=True):
     stdtracks()
     try:
         module.test()
     stdtracks()
     try:
         module.test()
-    finally:
-        stop_daemon()
+    except:
+        traceback.print_exc(None, sys.stderr)
+        failures += 1
+    stop_daemon()
     if report:
         if failures:
             print " FAILED"
     if report:
         if failures:
             print " FAILED"
diff --git a/tests/fail.py b/tests/fail.py
new file mode 100755 (executable)
index 0000000..9d7f081
--- /dev/null
@@ -0,0 +1,28 @@
+#! /usr/bin/env python
+#
+# This file is part of DisOrder.
+# Copyright (C) 2009 Richard Kettlewell
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+import dtest
+
+def test():
+    """Create a daemon and fail"""
+    dtest.start_daemon()
+    dtest.create_user()
+    assert True == False, "forcing failure"
+
+if __name__ == '__main__':
+    dtest.run()