summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLewis Haley <lewis.haley@youview.com>2015-09-24 12:43:08 +0100
committerLewis Haley <lewis.haley@youview.com>2015-10-16 17:39:19 +0100
commit0164f01e4804940b92459ac7f52eb5d021506be6 (patch)
treebfd9b0353502b3b2d0a4397a40472927590de6ed
parent96b05390e31a54a046524455f9b781c069d66857 (diff)
downloadnose-0164f01e4804940b92459ac7f52eb5d021506be6.tar.gz
nose/case.{Function,Method}TestCase: have consistent __repr__
Tests were added in the previous commit which showed that modifying a mutable object given as an argument to a test case during the execution of the test case results in the __repr__ of the test case also changing (if the __repr__ of the object also changed). This was caused by creating a __repr__ of the test args on the fly, and because the summary line is printed *before* the test is executed and failure details are printed *after* the test is executed, this can result in the two lines having different __repr__s of the passed in arguments (see the previous commit message for an example of the output). This commit fixes the issue by storing a __repr__ of the argument tuple when the *TestCase is instantiated and using that to create all __repr__s of the *TestCase. Note that the `if` for when no args are given had to be changed because `repr(tuple())` is '()', which is truthy.
-rw-r--r--nose/case.py14
1 files changed, 8 insertions, 6 deletions
diff --git a/nose/case.py b/nose/case.py
index cffa4ab..e5a407a 100644
--- a/nose/case.py
+++ b/nose/case.py
@@ -239,6 +239,7 @@ class FunctionTestCase(TestBase):
self.setUpFunc = setUp
self.tearDownFunc = tearDown
self.arg = arg
+ self.arg_repr = repr(self.arg)
self.descriptor = descriptor
TestBase.__init__(self)
@@ -282,7 +283,7 @@ class FunctionTestCase(TestBase):
else:
name = func.__name__
name = "%s.%s" % (func.__module__, name)
- if arg:
+ if not arg == '()':
name = "%s%s" % (name, arg)
# FIXME need to include the full dir path to disambiguate
# in cases where test module of the same name was seen in
@@ -299,9 +300,9 @@ class FunctionTestCase(TestBase):
are returned.
"""
if self.descriptor:
- return self.descriptor, self.arg
+ return self.descriptor, self.arg_repr
else:
- return self.test, self.arg
+ return self.test, self.arg_repr
class MethodTestCase(TestBase):
@@ -338,6 +339,7 @@ class MethodTestCase(TestBase):
self.method = method
self.test = test
self.arg = arg
+ self.arg_repr = repr(self.arg)
self.descriptor = descriptor
if isfunction(method):
raise ValueError("Unbound methods must be wrapped using pyversion.unbound_method before passing to MethodTestCase")
@@ -357,7 +359,7 @@ class MethodTestCase(TestBase):
name = "%s.%s.%s" % (self.cls.__module__,
self.cls.__name__,
name)
- if arg:
+ if not arg == '()':
name = "%s%s" % (name, arg)
return name
__repr__ = __str__
@@ -392,6 +394,6 @@ class MethodTestCase(TestBase):
or function are returned.
"""
if self.descriptor:
- return self.descriptor, self.arg
+ return self.descriptor, self.arg_repr
else:
- return self.method, self.arg
+ return self.method, self.arg_repr