summaryrefslogtreecommitdiffstats
path: root/Lib/unittest/mock.py
diff options
context:
space:
mode:
authorMichael Foord <michael@voidspace.org.uk>2014-04-14 20:25:20 (GMT)
committerMichael Foord <michael@voidspace.org.uk>2014-04-14 20:25:20 (GMT)
commitfddcfa27fab71ceb6a9df3f4edf46e94ee1da94f (patch)
treee2023b0ee586885b354d62492d14b95f5b3a57cb /Lib/unittest/mock.py
parentfba913f77aa53dff416753c987bf590762c98406 (diff)
downloadcpython-fddcfa27fab71ceb6a9df3f4edf46e94ee1da94f.zip
cpython-fddcfa27fab71ceb6a9df3f4edf46e94ee1da94f.tar.gz
cpython-fddcfa27fab71ceb6a9df3f4edf46e94ee1da94f.tar.bz2
Closes issue 17660. You no longer need to explicitly pass create=True when patching builtin names.
Diffstat (limited to 'Lib/unittest/mock.py')
-rw-r--r--Lib/unittest/mock.py7
1 files changed, 7 insertions, 0 deletions
diff --git a/Lib/unittest/mock.py b/Lib/unittest/mock.py
index f1f6522..2dd4ca5 100644
--- a/Lib/unittest/mock.py
+++ b/Lib/unittest/mock.py
@@ -27,9 +27,13 @@ __version__ = '1.0'
import inspect
import pprint
import sys
+import builtins
+from types import ModuleType
from functools import wraps, partial
+_builtins = {name for name in dir(builtins) if not name.startswith('_')}
+
BaseExceptions = (BaseException,)
if 'java' in sys.platform:
# jython
@@ -1166,6 +1170,9 @@ class _patch(object):
else:
local = True
+ if name in _builtins and isinstance(target, ModuleType):
+ self.create = True
+
if not self.create and original is DEFAULT:
raise AttributeError(
"%s does not have the attribute %r" % (target, name)