Skip to content

Commit 8c7d912

Browse files
switch num_mock_patch_args to do identity checks for the sentinels
1 parent 240d314 commit 8c7d912

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

src/_pytest/compat.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,18 @@ def num_mock_patch_args(function):
6464
patchings = getattr(function, "patchings", None)
6565
if not patchings:
6666
return 0
67-
mock_modules = [sys.modules.get("mock"), sys.modules.get("unittest.mock")]
68-
if any(mock_modules):
69-
sentinels = [m.DEFAULT for m in mock_modules if m is not None]
70-
return len(
71-
[p for p in patchings if not p.attribute_name and p.new in sentinels]
72-
)
73-
return len(patchings)
67+
68+
mock_sentinel = getattr(sys.modules.get("mock"), "DEFAULT", object())
69+
ut_mock_sentinel = getattr(sys.modules.get("unittest.mock"), "DEFAULT", object())
70+
71+
return len(
72+
[
73+
p
74+
for p in patchings
75+
if not p.attribute_name
76+
and (p.new is mock_sentinel or p.new is ut_mock_sentinel)
77+
]
78+
)
7479

7580

7681
def getfuncargnames(function, is_method=False, cls=None):

0 commit comments

Comments
 (0)