From adbf178e49113b2de0042e86a1228560475a65c5 Mon Sep 17 00:00:00 2001 From: Chris Withers Date: Wed, 1 May 2019 23:04:04 +0100 Subject: Mock 100% coverage (GH-13045) This was achieved by: * moving many pass statements in tests onto their own lines, so they pass line coverage and can match an easy ignore pattern if branch coverage is added later. * removing code that cannot be reached. * removing long-disabled tests. * removing unused code. * adding tests for uncovered code It turned out that removing `if __name__ == '__main__'` blocks that run unittest.main() at the bottom of test files was surprisingly contentious, so they remain and can be filtered out with an appropriate .coveragerc. --- Lib/unittest/test/testmock/testwith.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'Lib/unittest/test/testmock/testwith.py') diff --git a/Lib/unittest/test/testmock/testwith.py b/Lib/unittest/test/testmock/testwith.py index ec4e540dcfd..37100b8c183 100644 --- a/Lib/unittest/test/testmock/testwith.py +++ b/Lib/unittest/test/testmock/testwith.py @@ -10,6 +10,8 @@ something = sentinel.Something something_else = sentinel.SomethingElse +class SampleException(Exception): pass + class WithTest(unittest.TestCase): @@ -20,14 +22,10 @@ class WithTest(unittest.TestCase): def test_with_statement_exception(self): - try: + with self.assertRaises(SampleException): with patch('%s.something' % __name__, sentinel.Something2): self.assertEqual(something, sentinel.Something2, "unpatched") - raise Exception('pow') - except Exception: - pass - else: - self.fail("patch swallowed exception") + raise SampleException() self.assertEqual(something, sentinel.Something) @@ -128,8 +126,7 @@ class WithTest(unittest.TestCase): def test_double_patch_instance_method(self): class C: - def f(self): - pass + def f(self): pass c = C() -- cgit v1.2.3