Skip to content

Commit eb3a3dd

Browse files
elazarggvanrossum
authored andcommitted
Migrate stdlibsamples test to pytest (#5271)
Check as files instead of as modules, without changing cwd.
1 parent 88a6a4e commit eb3a3dd

File tree

2 files changed

+12
-16
lines changed

2 files changed

+12
-16
lines changed

mypy/test/testsamples.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,18 @@ def test_samples(self) -> None:
3434
mypy_args.append('--python-version=3.5')
3535
run_mypy(mypy_args + [f])
3636

37+
def test_stdlibsamples(self) -> None:
38+
seen = set() # type: Set[str]
39+
stdlibsamples_dir = os.path.join('test-data', 'stdlib-samples', '3.2', 'test')
40+
modules = [] # type: List[str]
41+
for f in find_files(stdlibsamples_dir, prefix='test_', suffix='.py'):
42+
if f not in seen:
43+
seen.add(f)
44+
modules.append(f)
45+
if modules:
46+
# TODO: Remove need for --no-strict-optional
47+
run_mypy(['--no-strict-optional'] + modules)
48+
3749

3850
def find_files(base: str, prefix: str = '', suffix: str = '') -> List[str]:
3951
return [os.path.join(root, f)

runtests.py

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -158,21 +158,6 @@ def add_pytest(driver: Driver) -> None:
158158
[('self-check', name) for name in SELFCHECK_FILES])
159159

160160

161-
def add_stdlibsamples(driver: Driver) -> None:
162-
seen = set() # type: Set[str]
163-
stdlibsamples_dir = join(driver.cwd, 'test-data', 'stdlib-samples', '3.2', 'test')
164-
modules = [] # type: List[str]
165-
for f in find_files(stdlibsamples_dir, prefix='test_', suffix='.py'):
166-
module = file_to_module(f[len(stdlibsamples_dir) + 1:])
167-
if module not in seen:
168-
seen.add(module)
169-
modules.append(module)
170-
if modules:
171-
# TODO: Remove need for --no-strict-optional
172-
driver.add_mypy_modules('stdlibsamples (3.2)', modules,
173-
cwd=stdlibsamples_dir, extra_args=['--no-strict-optional'])
174-
175-
176161
def usage(status: int) -> None:
177162
print('Usage: %s [-h | -v | -q | --lf | --ff | [-x] FILTER | -a ARG | -p ARG]'
178163
'... [-- FILTER ...]'
@@ -310,7 +295,6 @@ def main() -> None:
310295

311296
driver.add_flake8()
312297
add_pytest(driver)
313-
add_stdlibsamples(driver)
314298

315299
if list_only:
316300
driver.list_tasks()

0 commit comments

Comments
 (0)