[Python-checkins] cpython: unittest.mock: set file_spec on first use

michael.foord python-checkins at python.org
Sun Mar 25 20:11:59 CEST 2012


http://hg.python.org/cpython/rev/058396f89fea
changeset:   75927:058396f89fea
user:        Michael Foord <michael at voidspace.org.uk>
date:        Sun Mar 25 19:03:13 2012 +0100
summary:
  unittest.mock: set file_spec on first use

files:
  Lib/unittest/mock.py |  10 +++++++---
  1 files changed, 7 insertions(+), 3 deletions(-)


diff --git a/Lib/unittest/mock.py b/Lib/unittest/mock.py
--- a/Lib/unittest/mock.py
+++ b/Lib/unittest/mock.py
@@ -2138,11 +2138,15 @@
     '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)
 

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list