diff options
Diffstat (limited to 'unit_tests')
-rw-r--r-- | unit_tests/test_cases.py | 40 | ||||
-rw-r--r-- | unit_tests/test_logcapture_plugin.py | 18 |
2 files changed, 58 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): diff --git a/unit_tests/test_logcapture_plugin.py b/unit_tests/test_logcapture_plugin.py index 63aa651..1f2d50f 100644 --- a/unit_tests/test_logcapture_plugin.py +++ b/unit_tests/test_logcapture_plugin.py @@ -255,3 +255,21 @@ class TestLogCapturePlugin(object): assert msg in ev else: assert msg.encode('utf-8') in ev + + def test_non_propagating_loggers_handled(self): + c = LogCapture() + parser = OptionParser() + c.addOptions(parser, {}) + options, args = parser.parse_args([]) + c.configure(options, Config()) + + logger = logging.getLogger('foo.yes') + logger.propagate = False + + c.start() + logger.debug("test message") + c.end() + + records = c.formatLogRecords() + eq_(1, len(records)) + assert records[0].startswith('foo.yes:'), records[0] |