summaryrefslogtreecommitdiffstats
path: root/Lib/unittest
diff options
context:
space:
mode:
authorMichael Foord <michael@voidspace.org.uk>2012-03-25 18:03:13 (GMT)
committerMichael Foord <michael@voidspace.org.uk>2012-03-25 18:03:13 (GMT)
commita74561a56d58187ebfdad25104486bbcd08e1de6 (patch)
treee2b06fe1c13fc755316e7cebc152f64970bd9af7 /Lib/unittest
parent50a8c0ef5d6c7ae213d86940cc842c0f73fb273a (diff)
downloadcpython-a74561a56d58187ebfdad25104486bbcd08e1de6.zip
cpython-a74561a56d58187ebfdad25104486bbcd08e1de6.tar.gz
cpython-a74561a56d58187ebfdad25104486bbcd08e1de6.tar.bz2
unittest.mock: set file_spec on first use
Diffstat (limited to 'Lib/unittest')
-rw-r--r--Lib/unittest/mock.py8
1 files changed, 6 insertions, 2 deletions
diff --git a/Lib/unittest/mock.py b/Lib/unittest/mock.py
index 9a0bbf0..6ecc4c7 100644
--- a/Lib/unittest/mock.py
+++ b/Lib/unittest/mock.py
@@ -2138,11 +2138,15 @@ FunctionAttributes = set([
'func_name',
])
-import _io
-file_spec = list(set(dir(_io.TextIOWrapper)).union(set(dir(_io.BytesIO))))
+file_spec = None
def mock_open(mock=None, read_data=None):
+ global file_spec
+ if file_spec is None:
+ import _io
+ file_spec = list(set(dir(_io.TextIOWrapper)).union(set(dir(_io.BytesIO))))
+
if mock is None:
mock = MagicMock(spec=file_spec)