diff options
Diffstat (limited to 'Lib/unittest')
-rw-r--r-- | Lib/unittest/__main__.py | 9 | ||||
-rw-r--r-- | Lib/unittest/mock.py | 4 | ||||
-rw-r--r-- | Lib/unittest/runner.py | 2 | ||||
-rw-r--r-- | Lib/unittest/test/test_runner.py | 13 | ||||
-rw-r--r-- | Lib/unittest/test/testmock/testmock.py | 7 |
5 files changed, 31 insertions, 4 deletions
diff --git a/Lib/unittest/__main__.py b/Lib/unittest/__main__.py index 7320050..798ebc0 100644 --- a/Lib/unittest/__main__.py +++ b/Lib/unittest/__main__.py @@ -2,7 +2,14 @@ import sys if sys.argv[0].endswith("__main__.py"): - sys.argv[0] = "python -m unittest" + import os.path + # We change sys.argv[0] to make help message more useful + # use executable without path, unquoted + # (it's just a hint anyway) + # (if you have spaces in your executable you get what you deserve!) + executable = os.path.basename(sys.executable) + sys.argv[0] = executable + " -m unittest" + del os __unittest = True diff --git a/Lib/unittest/mock.py b/Lib/unittest/mock.py index 95570aa..324cf39 100644 --- a/Lib/unittest/mock.py +++ b/Lib/unittest/mock.py @@ -731,8 +731,8 @@ class NonCallableMock(Base): arguments.""" self = _mock_self if not self.call_count == 1: - msg = ("Expected to be called once. Called %s times." % - self.call_count) + msg = ("Expected '%s' to be called once. Called %s times." % + (self._mock_name or 'mock', self.call_count)) raise AssertionError(msg) return self.assert_called_with(*args, **kwargs) diff --git a/Lib/unittest/runner.py b/Lib/unittest/runner.py index 10c4778..28b8865 100644 --- a/Lib/unittest/runner.py +++ b/Lib/unittest/runner.py @@ -35,7 +35,7 @@ class TextTestResult(result.TestResult): separator2 = '-' * 70 def __init__(self, stream, descriptions, verbosity): - super(TextTestResult, self).__init__() + super(TextTestResult, self).__init__(stream, descriptions, verbosity) self.stream = stream self.showAll = verbosity > 1 self.dots = verbosity == 1 diff --git a/Lib/unittest/test/test_runner.py b/Lib/unittest/test/test_runner.py index 8e95410..aed1e76 100644 --- a/Lib/unittest/test/test_runner.py +++ b/Lib/unittest/test/test_runner.py @@ -149,6 +149,19 @@ class Test_TextTestRunner(unittest.TestCase): self.assertEqual(runner.resultclass, unittest.TextTestResult) + def test_multiple_inheritance(self): + class AResult(unittest.TestResult): + def __init__(self, stream, descriptions, verbosity): + super(AResult, self).__init__(stream, descriptions, verbosity) + + class ATextResult(unittest.TextTestResult, AResult): + pass + + # This used to raise an exception due to TextTestResult not passing + # on arguments in its __init__ super call + ATextResult(None, None, 1) + + def testBufferAndFailfast(self): class Test(unittest.TestCase): def testFoo(self): diff --git a/Lib/unittest/test/testmock/testmock.py b/Lib/unittest/test/testmock/testmock.py index 64fd1a1..2c6f128 100644 --- a/Lib/unittest/test/testmock/testmock.py +++ b/Lib/unittest/test/testmock/testmock.py @@ -463,6 +463,13 @@ class MockTest(unittest.TestCase): mock.assert_called_with) + def test_assert_called_once_with_message(self): + mock = Mock(name='geoffrey') + self.assertRaisesRegex(AssertionError, + r"Expected 'geoffrey' to be called once\.", + mock.assert_called_once_with) + + def test__name__(self): mock = Mock() self.assertRaises(AttributeError, lambda: mock.__name__) |