Skip to content

Fixed Auto Discovery of .test files Fixes #8650 #10108

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 2 commits into from
Closed
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
95 changes: 18 additions & 77 deletions mypy/test/testcheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,87 +24,28 @@


# List of files that contain test case descriptions.
typecheck_files = [
'check-basic.test',
'check-union-or-syntax.test',
'check-callable.test',
'check-classes.test',
'check-statements.test',
'check-generics.test',
'check-dynamic-typing.test',
'check-inference.test',
'check-inference-context.test',
'check-kwargs.test',
'check-overloading.test',
'check-type-checks.test',
'check-abstract.test',
'check-multiple-inheritance.test',
'check-super.test',
'check-modules.test',
'check-typevar-values.test',
'check-unsupported.test',
'check-unreachable-code.test',
'check-unions.test',
'check-isinstance.test',
'check-lists.test',
'check-namedtuple.test',
'check-narrowing.test',
'check-typeddict.test',
'check-type-aliases.test',
'check-ignore.test',
'check-type-promotion.test',
'check-semanal-error.test',
'check-flags.test',
'check-incremental.test',
'check-serialize.test',
'check-bound.test',
'check-optional.test',
'check-fastparse.test',
'check-warnings.test',
'check-async-await.test',
'check-newtype.test',
'check-class-namedtuple.test',
'check-selftype.test',
'check-python2.test',
'check-columns.test',
'check-functions.test',
'check-tuples.test',
'check-expressions.test',
'check-generic-subtyping.test',
'check-varargs.test',
'check-newsyntax.test',
'check-protocols.test',
'check-underscores.test',
'check-classvar.test',
'check-enum.test',
'check-incomplete-fixture.test',
'check-custom-plugin.test',
'check-default-plugin.test',
'check-attr.test',
'check-ctypes.test',
'check-dataclasses.test',
'check-final.test',
'check-redefine.test',
'check-literal.test',
'check-newsemanal.test',
'check-inline-config.test',
'check-reports.test',
'check-errorcodes.test',
'check-annotated.test',
'check-parameter-specification.test',
'check-generic-alias.test',
'check-typeguard.test',
]
typecheck_files = []

# Define the path where the check files are present.
if sys.platform == 'win32':
path2loc = os.path.abspath(__file__).split('mypy\\test')[0] + 'test-data\\unit'
else:
path2loc = os.path.join(os.path.abspath(__file__).split('mypy/test')[0], 'test-data/unit')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is hard to reason about. Can you unify the cases so that the same implementation works on both Windows and other platforms? You can probably use os.path.join and/or os.sep.


for check_files in os.listdir(path2loc):
# Append only if it has the pattern ( check-*-*.test)
if re.match(r'check-\w+-?\w+?-?\w+?.test', check_files):
typecheck_files.append(check_files)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you move this and the above logic to a helper module, so that this can be reused in other places easily?

For example, we could have something like this in this file:

typecheck_files = expand_test_files('test-data/unit/check-*.test')

You can use glob.glob to expand patterns instead of re, since regular expressions are more error-prone as they require escaping, etc.


# Tests that use Python 3.8-only AST features (like expression-scoped ignores):
if sys.version_info >= (3, 8):
typecheck_files.append('check-python38.test')
if sys.version_info >= (3, 9):
typecheck_files.append('check-python39.test')
if sys.version_info < (3, 8):
typecheck_files.remove('check-python38.test')
if sys.version_info < (3, 9):
typecheck_files.remove('check-python39.test')

# Special tests for platforms with case-insensitive filesystems.
if sys.platform in ('darwin', 'win32'):
typecheck_files.append('check-modules-case.test')
if sys.platform not in ('darwin', 'win32'):
typecheck_files.remove('check-modules-case.test')


class TypeCheckSuite(DataSuite):
Expand Down