Skip to content

Commit 04091c0

Browse files
authored
unittest.mock test and coverage fixup (python#130787)
* Mark functions that will never be called with # pragma: no cover * Fix testpatch.PatchTest.test_exit_idempotent .stop() and __exit__ have subtly different code paths, so to really test __exit__ idempotency, we need to call it specifically twice.
1 parent f693f84 commit 04091c0

File tree

3 files changed

+3
-3
lines changed

3 files changed

+3
-3
lines changed

Lib/test/test_unittest/testmock/testhelpers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1080,7 +1080,7 @@ def test_dataclass_with_method(self):
10801080
class WithMethod:
10811081
a: int
10821082
def b(self) -> int:
1083-
return 1
1083+
return 1 # pragma: no cover
10841084

10851085
for mock in [
10861086
create_autospec(WithMethod, instance=True),

Lib/test/test_unittest/testmock/testmock.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ def test_explicit_return_value_even_if_mock_wraps_object(self):
316316
passed to the wrapped object and the return_value is returned instead.
317317
"""
318318
def my_func():
319-
return None
319+
return None # pragma: no cover
320320
func_mock = create_autospec(spec=my_func, wraps=my_func)
321321
return_value = "explicit return value"
322322
func_mock.return_value = return_value

Lib/test/test_unittest/testmock/testpatch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,7 @@ def test_stop_idempotent(self):
748748
def test_exit_idempotent(self):
749749
patcher = patch(foo_name, 'bar', 3)
750750
with patcher:
751-
patcher.stop()
751+
patcher.__exit__(None, None, None)
752752

753753

754754
def test_second_start_failure(self):

0 commit comments

Comments
 (0)