Skip to content

Add mypy.test.config.ALLOW_FIXTURES #3112

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions mypy/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions mypy/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 6 additions & 2 deletions mypy/test/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

from mypy.myunit import TestCase, SkipTestCaseException

from mypy.defaults import ALLOW_FIXTURES


def parse_test_cases(
path: str,
Expand Down Expand Up @@ -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'):
Expand All @@ -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:
Expand Down