diff options
-rw-r--r-- | Lib/unittest/mock.py | 8 |
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) |