Skip to content

Commit 6c24919

Browse files
committed
move stubgen to pytest; fix name-filtering regression
1 parent c1e96f5 commit 6c24919

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

mypy/test/teststubgen.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
from mypy.myunit import Suite, AssertionFailure, assert_equal
1515
from mypy.test.helpers import assert_string_arrays_equal
16-
from mypy.test.data import parse_test_cases, DataDrivenTestCase
16+
from mypy.test.data import DataSuite, parse_test_cases, DataDrivenTestCase
1717
from mypy.test import config
1818
from mypy.parse import parse
1919
from mypy.errors import CompileError
@@ -95,15 +95,19 @@ def test_infer_sig_from_docstring(self) -> None:
9595
assert_equal(infer_sig_from_docstring('\nfunc x', 'func'), None)
9696

9797

98-
class StubgenPythonSuite(Suite):
98+
class StubgenPythonSuite(DataSuite):
9999
test_data_files = ['stubgen.test']
100100

101-
def cases(self) -> List[DataDrivenTestCase]:
101+
@classmethod
102+
def cases(cls) -> List[DataDrivenTestCase]:
102103
c = [] # type: List[DataDrivenTestCase]
103-
for path in self.test_data_files:
104+
for path in cls.test_data_files:
104105
c += parse_test_cases(os.path.join(config.test_data_prefix, path), test_stubgen)
105106
return c
106107

108+
def run_case(self, testcase: DataDrivenTestCase) -> None:
109+
test_stubgen(testcase)
110+
107111

108112
def parse_flags(program_text: str) -> Options:
109113
flags = re.search('# flags: (.*)$', program_text, flags=re.MULTILINE)

runtests.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -89,17 +89,17 @@ def add_mypy_package(self, name: str, packagename: str, *flags: str) -> None:
8989
def add_mypy_string(self, name: str, *args: str, cwd: Optional[str] = None) -> None:
9090
self.add_mypy_cmd(name, ['-c'] + list(args), cwd=cwd)
9191

92-
def add_pytest(self, name: str, pytest_files: List[str], coverage: bool = True) -> None:
93-
pytest_args = pytest_files + self.arglist + self.pyt_arglist
94-
full_name = 'pytest %s' % name
95-
if not self.allow(full_name):
92+
def add_pytest(self, pytest_files: List[str], coverage: bool = True) -> None:
93+
pytest_files = [name for name in pytest_files if self.allow(name[4:])]
94+
if not pytest_files:
9695
return
96+
pytest_args = pytest_files + self.arglist + self.pyt_arglist
9797
if coverage and self.coverage:
9898
args = [sys.executable, '-m', 'pytest', '--cov=mypy'] + pytest_args
9999
else:
100100
args = [sys.executable, '-m', 'pytest'] + pytest_args
101101

102-
self.waiter.add(LazySubprocess(full_name, args, env=self.env, passthrough=self.verbosity),
102+
self.waiter.add(LazySubprocess('pytest', args, env=self.env, passthrough=self.verbosity),
103103
sequential=True)
104104

105105
def add_python(self, name: str, *args: str, cwd: Optional[str] = None) -> None:
@@ -212,12 +212,12 @@ def test_path(*names: str):
212212
'testparse',
213213
'testsemanal',
214214
'testpythoneval',
215-
'testcmdline'
215+
'testcmdline',
216+
'teststubgen'
216217
)
217218

218219
MYUNIT_FILES = test_path(
219-
'teststubgen', # contains data-driven suite
220-
220+
'teststubgen',
221221
'testargs',
222222
'testgraph',
223223
'testinfer',
@@ -233,7 +233,7 @@ def test_path(*names: str):
233233

234234

235235
def add_pytest(driver: Driver) -> None:
236-
driver.add_pytest('pytest', PYTEST_FILES)
236+
driver.add_pytest(PYTEST_FILES)
237237

238238

239239
def add_myunit(driver: Driver) -> None:

0 commit comments

Comments
 (0)