diff --git a/mypy/build.py b/mypy/build.py index 682fa1e00398..3a5fb6b66542 100644 --- a/mypy/build.py +++ b/mypy/build.py @@ -42,6 +42,7 @@ from mypy.stats import dump_type_stats from mypy.types import Type from mypy.version import __version__ +from mypy.defaults import ALLOW_FIXTURES # We need to know the location of this file to load data, but @@ -143,8 +144,9 @@ def build(sources: List[BuildSource], # debug). This is a test-only feature, so assume our files are laid out # as in the source tree. root_dir = dirname(dirname(__file__)) - lib_path.insert(0, os.path.join(root_dir, 'test-data', 'unit', 'lib-stub')) - else: + if ALLOW_FIXTURES: + lib_path.insert(0, os.path.join(root_dir, 'test-data', 'unit', 'lib-stub')) + if not options.use_builtins_fixtures or not ALLOW_FIXTURES: for source in sources: if source.path: # Include directory of the program file in the module search path. diff --git a/mypy/defaults.py b/mypy/defaults.py index b5398f990d11..d6707925ff8c 100644 --- a/mypy/defaults.py +++ b/mypy/defaults.py @@ -2,3 +2,5 @@ PYTHON3_VERSION = (3, 6) CACHE_DIR = '.mypy_cache' CONFIG_FILE = 'mypy.ini' +# Set this to False (here in the file, not dynamically!) to disable builtins fixtures in tests +ALLOW_FIXTURES = True diff --git a/mypy/test/data.py b/mypy/test/data.py index a0573d55479c..0885af3ca2f1 100644 --- a/mypy/test/data.py +++ b/mypy/test/data.py @@ -12,6 +12,8 @@ from mypy.myunit import TestCase, SkipTestCaseException +from mypy.defaults import ALLOW_FIXTURES + def parse_test_cases( path: str, @@ -63,7 +65,8 @@ def parse_test_cases( assert arg is not None file_entry = (join(base_path, arg), '\n'.join(p[i].data)) if p[i].id == 'file': - files.append(file_entry) + if arg != 'builtins.py' or ALLOW_FIXTURES: + files.append(file_entry) elif p[i].id == 'outfile': output_files.append(file_entry) elif p[i].id in ('builtins', 'builtins_py2'): @@ -77,7 +80,8 @@ def parse_test_cases( # Python 2 fnam = '__builtin__.pyi' with open(mpath) as f: - files.append((join(base_path, fnam), f.read())) + if ALLOW_FIXTURES: + files.append((join(base_path, fnam), f.read())) elif p[i].id == 'stale': arg = p[i].arg if arg is None: