mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
unittest.mock: set file_spec on first use
This commit is contained in:
parent
50a8c0ef5d
commit
a74561a56d
1 changed files with 6 additions and 2 deletions
|
@ -2138,11 +2138,15 @@ FunctionAttributes = set([
|
||||||
'func_name',
|
'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):
|
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:
|
if mock is None:
|
||||||
mock = MagicMock(spec=file_spec)
|
mock = MagicMock(spec=file_spec)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue