diff options
author | nkozlovskiy <nmk@ydb.tech> | 2023-09-29 12:24:06 +0300 |
---|---|---|
committer | nkozlovskiy <nmk@ydb.tech> | 2023-09-29 12:41:34 +0300 |
commit | e0e3e1717e3d33762ce61950504f9637a6e669ed (patch) | |
tree | bca3ff6939b10ed60c3d5c12439963a1146b9711 /contrib/python/pytest-mock/py3/pytest_mock/_util.py | |
parent | 38f2c5852db84c7b4d83adfcb009eb61541d1ccd (diff) | |
download | ydb-e0e3e1717e3d33762ce61950504f9637a6e669ed.tar.gz |
add ydb deps
Diffstat (limited to 'contrib/python/pytest-mock/py3/pytest_mock/_util.py')
-rw-r--r-- | contrib/python/pytest-mock/py3/pytest_mock/_util.py | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/contrib/python/pytest-mock/py3/pytest_mock/_util.py b/contrib/python/pytest-mock/py3/pytest_mock/_util.py new file mode 100644 index 0000000000..d3a732ac27 --- /dev/null +++ b/contrib/python/pytest-mock/py3/pytest_mock/_util.py @@ -0,0 +1,36 @@ +from typing import Union + +_mock_module = None + + +def get_mock_module(config): + """ + Import and return the actual "mock" module. By default this is + "unittest.mock", but the user can force to always use "mock" using + the mock_use_standalone_module ini option. + """ + global _mock_module + if _mock_module is None: + use_standalone_module = parse_ini_boolean( + config.getini("mock_use_standalone_module") + ) + if use_standalone_module: + import mock + + _mock_module = mock + else: + import unittest.mock + + _mock_module = unittest.mock + + return _mock_module + + +def parse_ini_boolean(value: Union[bool, str]) -> bool: + if isinstance(value, bool): + return value + if value.lower() == "true": + return True + if value.lower() == "false": + return False + raise ValueError("unknown string for bool: %r" % value) |