Skip to content

Commit f639e1b

Browse files
elazargmsullivan
authored andcommitted
Add self-check to pytests (#5087)
1 parent 46fefce commit f639e1b

File tree

4 files changed

+39
-18
lines changed

4 files changed

+39
-18
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ install:
1616
- pip install .
1717

1818
script:
19-
- python runtests.py -j12 -x lint -x package
19+
- python runtests.py -j12 -x lint -x self-check
2020
- if [[ $TRAVIS_PYTHON_VERSION == '3.6' ]]; then flake8; fi
2121
- if [[ $TRAVIS_PYTHON_VERSION == '3.5.1' ]]; then python runtests.py package; fi

appveyor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ build: off
2121

2222
test_script:
2323
# Ignore lint and mypy self check (both run in Travis)
24-
- "%PYTHON%\\python.exe runtests.py -x lint -x package -x pytest"
24+
- "%PYTHON%\\python.exe runtests.py -x lint -x self-check -x pytest"
2525
- "%PYTHON%\\python.exe runtests.py pytest -p -k -p \"not (PythonEvaluationSuite and python2)\""
2626

2727
skip_commits:

mypy/test/testselfcheck.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
"""Self check mypy package"""
2+
import sys
3+
from typing import List
4+
5+
import pytest # type: ignore
6+
7+
from mypy.test.helpers import Suite
8+
from mypy.api import run
9+
10+
11+
class SelfCheckSuite(Suite):
12+
def test_mypy_package(self) -> None:
13+
run_mypy(['-p', 'mypy'])
14+
15+
def test_testrunner(self) -> None:
16+
run_mypy(['runtests.py', 'waiter.py'])
17+
18+
19+
def run_mypy(args: List[str]) -> None:
20+
__tracebackhide__ = True
21+
outval, errval, status = run(args + ['--config-file', 'mypy_self_check.ini',
22+
'--show-traceback',
23+
'--no-site-packages'])
24+
if status != 0:
25+
sys.stdout.write(outval)
26+
errval = '\n'.join(line for line in errval.split('\n')
27+
if 'mypy_self_check.ini' not in line)
28+
sys.stderr.write(errval)
29+
pytest.fail(msg="Self check failed", pytrace=False)

runtests.py

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -71,18 +71,12 @@ def add_mypy_cmd(self, name: str, mypy_args: List[str], cwd: Optional[str] = Non
7171
args.append('--no-site-packages')
7272
self.waiter.add(LazySubprocess(full_name, args, cwd=cwd, env=self.env))
7373

74-
def add_mypy(self, name: str, *args: str, cwd: Optional[str] = None) -> None:
75-
self.add_mypy_cmd(name, list(args), cwd=cwd)
76-
7774
def add_mypy_modules(self, name: str, modules: Iterable[str], cwd: Optional[str] = None,
7875
extra_args: Optional[List[str]] = None) -> None:
7976
args = extra_args or []
8077
args.extend(list(itertools.chain(*(['-m', mod] for mod in modules))))
8178
self.add_mypy_cmd(name, args, cwd=cwd)
8279

83-
def add_mypy_package(self, name: str, packagename: str, *flags: str) -> None:
84-
self.add_mypy_cmd(name, ['-p', packagename] + list(flags))
85-
8680
def add_pytest(self, files: List[Tuple[str, str]], coverage: bool = True) -> None:
8781
pytest_files = [name for kind, name in files
8882
if self.allow('pytest {} {}'.format(kind, name))]
@@ -111,12 +105,6 @@ def list_tasks(self) -> None:
111105
print('{id}:{task}'.format(id=id, task=task.name))
112106

113107

114-
def add_selftypecheck(driver: Driver) -> None:
115-
driver.add_mypy('file runtests.py', 'runtests.py')
116-
driver.add_mypy('file waiter.py', 'waiter.py')
117-
driver.add_mypy_package('package mypy', 'mypy', '--config-file', 'mypy_self_check.ini')
118-
119-
120108
def find_files(base: str, prefix: str = '', suffix: str = '') -> List[str]:
121109
return [join(root, f)
122110
for root, dirs, files in os.walk(base)
@@ -131,7 +119,7 @@ def file_to_module(file: str) -> str:
131119
return rv
132120

133121

134-
def test_path(*names: str):
122+
def test_path(*names: str) -> List[str]:
135123
return [os.path.join('mypy', 'test', '{}.py'.format(name))
136124
for name in names]
137125

@@ -168,12 +156,17 @@ def test_path(*names: str):
168156
'teststubgen',
169157
)
170158

159+
SELFCHECK_FILES = test_path(
160+
'testselfcheck',
161+
)
162+
171163

172164
def add_pytest(driver: Driver) -> None:
173165
for f in find_files('mypy', prefix='test', suffix='.py'):
174-
assert f in PYTEST_FILES + SLOW_FILES, f
166+
assert f in PYTEST_FILES + SLOW_FILES + SELFCHECK_FILES, f
175167
driver.add_pytest([('unit-test', name) for name in PYTEST_FILES] +
176-
[('integration', name) for name in SLOW_FILES])
168+
[('integration', name) for name in SLOW_FILES] +
169+
[('self-check', name) for name in SELFCHECK_FILES])
177170

178171

179172
def add_stubs(driver: Driver) -> None:
@@ -354,7 +347,6 @@ def main() -> None:
354347

355348
driver.add_flake8()
356349
add_pytest(driver)
357-
add_selftypecheck(driver)
358350
add_stubs(driver)
359351
add_stdlibsamples(driver)
360352
add_samples(driver)

0 commit comments

Comments
 (0)