From e663c61b1aee7aea8fada6166d37256dfdb25735 Mon Sep 17 00:00:00 2001 Message-Id: From: Mark Wooding Date: Sat, 23 May 2009 09:48:51 +0100 Subject: [PATCH] More graceful handling of test failure; the exception is now reported before the daemon is stopped, making it clearer where the failure was. Organization: Straylight/Edgeware From: Richard Kettlewell 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 | 2 +- tests/dtest.py | 12 +++++++----- tests/fail.py | 28 ++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 6 deletions(-) create mode 100755 tests/fail.py diff --git a/tests/Makefile.am b/tests/Makefile.am index 060d850..dfe7424 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -33,5 +33,5 @@ TESTS_ENVIRONMENT=${PYTHON} -u 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 diff --git a/tests/dtest.py b/tests/dtest.py index 38eadf8..dd3c3a2 100644 --- a/tests/dtest.py +++ b/tests/dtest.py @@ -1,7 +1,7 @@ #-*-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 @@ -19,7 +19,7 @@ """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""" @@ -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.""" - global tests + global tests, failures tests += 1 # Locate the test module if module is None: @@ -333,8 +333,10 @@ def run(module=None, report=True): stdtracks() try: module.test() - finally: - stop_daemon() + except: + traceback.print_exc(None, sys.stderr) + failures += 1 + stop_daemon() if report: if failures: print " FAILED" diff --git a/tests/fail.py b/tests/fail.py new file mode 100755 index 0000000..9d7f081 --- /dev/null +++ b/tests/fail.py @@ -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 . +# +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() -- [mdw]