Skip to content

Commit c555e90

Browse files
committed
Support multiple steps in command line tests
PythonCmdlineSuite uses DataDrivenTestCase, but inspects the test case properties rather than calling runtest(). Therefore it could parse tests with multiple steps, but during execution only one step was run.
1 parent ed248c8 commit c555e90

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

mypy/test/testcmdline.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,20 @@ class PythonCmdlineSuite(DataSuite):
3232
native_sep = True
3333

3434
def run_case(self, testcase: DataDrivenTestCase) -> None:
35-
test_python_cmdline(testcase)
36-
37-
38-
def test_python_cmdline(testcase: DataDrivenTestCase) -> None:
35+
if testcase.output2:
36+
for step in [1] + sorted(testcase.output2):
37+
try:
38+
test_python_cmdline(testcase, step)
39+
except AssertionError as ex:
40+
if ex.args:
41+
new_msg = '(step {}) {}'.format(step, ex.args[0])
42+
ex.args = (new_msg,) + ex.args[1:]
43+
raise
44+
else:
45+
test_python_cmdline(testcase)
46+
47+
48+
def test_python_cmdline(testcase: DataDrivenTestCase, step: int = 1) -> None:
3949
assert testcase.old_cwd is not None, "test was not properly set up"
4050
# Write the program to a file.
4151
program = '_program.py'
@@ -101,7 +111,8 @@ def test_python_cmdline(testcase: DataDrivenTestCase) -> None:
101111
obvious_result = 1 if out else 0
102112
if obvious_result != result:
103113
out.append('== Return code: {}'.format(result))
104-
assert_string_arrays_equal(testcase.output, out,
114+
expected_out = testcase.output if step == 1 else testcase.output2[step]
115+
assert_string_arrays_equal(expected_out, out,
105116
'Invalid output ({}, line {})'.format(
106117
testcase.file, testcase.line))
107118

0 commit comments

Comments
 (0)