]> granicus.if.org Git - python/commitdiff
unittest.mock: set file_spec on first use
authorMichael Foord <michael@voidspace.org.uk>
Sun, 25 Mar 2012 18:03:13 +0000 (19:03 +0100)
committerMichael Foord <michael@voidspace.org.uk>
Sun, 25 Mar 2012 18:03:13 +0000 (19:03 +0100)
Lib/unittest/mock.py

index 9a0bbf0fe3fcf66eb39c9cf5118c063b865d2c82..6ecc4c71f68e44373fef0b41e4d372971a39c014 100644 (file)
@@ -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)