From a74561a56d58187ebfdad25104486bbcd08e1de6 Mon Sep 17 00:00:00 2001 From: Michael Foord Date: Sun, 25 Mar 2012 19:03:13 +0100 Subject: unittest.mock: set file_spec on first use --- Lib/unittest/mock.py | 8 ++++++-- 1 file 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) -- cgit v0.12