summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLewis Haley <lewis.haley@youview.com>2015-09-24 12:27:12 +0100
committerLewis Haley <lewis.haley@youview.com>2015-10-16 17:39:19 +0100
commit96b05390e31a54a046524455f9b781c069d66857 (patch)
treec4383ee5ede3f46edd565fc854dbaa2c5c2fa36d
parentd6642085a87cece41edc3808749f68d7b9a5ecd9 (diff)
downloadnose-96b05390e31a54a046524455f9b781c069d66857.tar.gz
unit_tests/test_cases: add tests for {Function,Method}TestCase.__repr__
At present, if a mutable argument is changed during the execution of test case, then any printing of the test case object which occurs after the test has run will result in the argument being printed with a __repr__ of it's *new* state (assuming that its __repr__ is state-dependant). This is particularly confusing when debugging failing test cases because the summary lines and the failure-detail lines will show *different* __repr__s of the args, e.g. nose_weirdness.test_nose_is_weird(Foo(10), 0) ... FAIL ====================================================================== FAIL: nose_weirdness.test_nose_is_weird(Foo(0), 0) ---------------------------------------------------------------------- ... Ran 1 test in 0.001s FAILED (failures=1) This issue will be solved in the next commit.
-rw-r--r--unit_tests/test_cases.py40
1 files changed, 40 insertions, 0 deletions
diff --git a/unit_tests/test_cases.py b/unit_tests/test_cases.py
index af399e5..fd5302d 100644
--- a/unit_tests/test_cases.py
+++ b/unit_tests/test_cases.py
@@ -115,6 +115,46 @@ class TestNoseCases(unittest.TestCase):
f(res)
assert res.errors
+ def test_FunctionTestCase_repr_is_consistent_with_mutable_args(self):
+ class Foo(object):
+ def __init__(self):
+ self.bar = 'unmodified'
+ def __repr__(self):
+ return "Foo(%s)" % self.bar
+
+ def test_foo(foo):
+ pass
+
+ foo = Foo()
+ case = nose.case.FunctionTestCase(test_foo, arg=(foo,))
+ case_repr_before = case.__repr__()
+ foo.bar = "snafu'd!"
+ case_repr_after = case.__repr__()
+ assert case_repr_before == case_repr_after, (
+ "Modifying a mutable object arg during test case changed the test "
+ "case's __repr__")
+
+ def test_MethodTestCase_repr_is_consistent_with_mutable_args(self):
+ class Foo(object):
+ def __init__(self):
+ self.bar = 'unmodified'
+ def __repr__(self):
+ return "Foo(%s)" % self.bar
+
+ class FooTester(object):
+ def test_foo(self, foo):
+ pass
+
+ foo = Foo()
+ case = nose.case.FunctionTestCase(
+ unbound_method(FooTester, FooTester.test_foo), arg=(foo,))
+ case_repr_before = case.__repr__()
+ foo.bar = "snafu'd!"
+ case_repr_after = case.__repr__()
+ assert case_repr_before == case_repr_after, (
+ "Modifying a mutable object arg during test case changed the test "
+ "case's __repr__")
+
class TestNoseTestWrapper(unittest.TestCase):
def test_case_fixtures_called(self):