Skip to content

Commit 4fc238e

Browse files
committed
unittest.mock test and coverage fixup (#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. Backports: 04091c083340dde7d4eeb6d945c70f3b37d88f85 Signed-off-by: Chris Withers <chris@withers.org>
1 parent aee44ed commit 4fc238e

File tree

3 files changed

+3
-3
lines changed

3 files changed

+3
-3
lines changed

mock/tests/testhelpers.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1097,7 +1097,7 @@ def test_dataclass_with_method(self):
10971097
class WithMethod:
10981098
a: int
10991099
def b(self) -> int:
1100-
return 1
1100+
return 1 # pragma: no cover
11011101

11021102
for mock in [
11031103
create_autospec(WithMethod, instance=True),

mock/tests/testmock.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ def test_explicit_return_value_even_if_mock_wraps_object(self):
317317
passed to the wrapped object and the return_value is returned instead.
318318
"""
319319
def my_func():
320-
return None
320+
return None # pragma: no cover
321321
func_mock = create_autospec(spec=my_func, wraps=my_func)
322322
return_value = "explicit return value"
323323
func_mock.return_value = return_value

mock/tests/testpatch.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -746,7 +746,7 @@ def test_stop_idempotent(self):
746746
def test_exit_idempotent(self):
747747
patcher = patch(foo_name, 'bar', 3)
748748
with patcher:
749-
patcher.stop()
749+
patcher.__exit__(None, None, None)
750750

751751

752752
def test_second_start_failure(self):

0 commit comments

Comments
 (0)