[Piglit] [PATCH 1/7] framework/tests/utils.py: Make the TestFailure exception message better
Dylan Baker
baker.dylan.c at gmail.com
Wed Sep 2 14:18:20 PDT 2015
This adds a better error message to TestFailure, which is raised by most
of the helpers in the utils module if a Test fails.
Signed-off-by: Dylan Baker <dylanx.c.baker at intel.com>
---
framework/tests/utils.py | 24 ++++++++++++++++++++++--
1 file changed, 22 insertions(+), 2 deletions(-)
diff --git a/framework/tests/utils.py b/framework/tests/utils.py
index 4829620..64aa0f5 100644
--- a/framework/tests/utils.py
+++ b/framework/tests/utils.py
@@ -85,7 +85,27 @@ _SAVED_COMPRESSION = os.environ.get('PIGLIT_COMPRESSION')
class TestFailure(AssertionError):
- pass
+ """An exception to be raised when a test fails.
+
+ Nose expects an AssertionError for test failures, so this is a sublcass of
+ AssertionError.
+
+ It provides the benefit of being able to take either a text message to
+ print, or an exception instance. When passed text it will print the message
+ exactly, when passed an exception it will print the exception type and the
+ str() value of that exception.
+
+ """
+ def __init__(self, arg):
+ super(TestFailure, self).__init__(self)
+ self.__arg = arg
+
+ def __str__(self):
+ if isinstance(self.__arg, Exception):
+ return 'exception type "{}" with message "{}" raised.'.format(
+ repr(self.__arg), str(self.__arg))
+ else:
+ return self.__arg
class UtilsError(Exception):
@@ -348,7 +368,7 @@ def not_raises(exceptions):
try:
func(*args, **kwargs)
except exceptions as e:
- raise TestFailure(str(e))
+ raise TestFailure(e)
return _inner
--
2.5.1
More information about the Piglit
mailing list