From 2e55c4ba61a67275fe594a14f5deccca1c923d76 Mon Sep 17 00:00:00 2001 From: Nicolas Delaby Date: Sun, 27 Jul 2014 12:11:39 +0200 Subject: [PATCH] unittest.mock from stdlib should come last --HG-- branch : mock-unittest-252 --- _pytest/python.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/_pytest/python.py b/_pytest/python.py index 2ddf83ef9..ac981ddb1 100644 --- a/_pytest/python.py +++ b/_pytest/python.py @@ -1866,8 +1866,10 @@ def handle_mock_module_patching(function, startindex): Special treatment when test_function is decorated by mock.patch """ - for candidate_module_name in ('unittest.mock', 'mock'): - # stdlib comes first + for candidate_module_name in ('mock', 'unittest.mock'): + # stdlib comes last, because mock might be also installed + # as a third party with upgraded version compare to + # unittest.mock try: mock = sys.modules[candidate_module_name] except KeyError: