Runs a suite of data test cases through pytest until either tests pass or until a maximum number of attempts (needed for incremental tests). :param data_suite: the actual "suite" i.e. the contents of a .test file
(
data_suite: str,
*,
data_file_prefix: str = "check",
pytest_node_prefix: str = "mypy/test/testcheck.py::TypeCheckSuite",
extra_args: Iterable[str],
max_attempts: int,
)
| 23 | |
| 24 | |
| 25 | def run_pytest_data_suite( |
| 26 | data_suite: str, |
| 27 | *, |
| 28 | data_file_prefix: str = "check", |
| 29 | pytest_node_prefix: str = "mypy/test/testcheck.py::TypeCheckSuite", |
| 30 | extra_args: Iterable[str], |
| 31 | max_attempts: int, |
| 32 | ) -> PytestResult: |
| 33 | """ |
| 34 | Runs a suite of data test cases through pytest until either tests pass |
| 35 | or until a maximum number of attempts (needed for incremental tests). |
| 36 | |
| 37 | :param data_suite: the actual "suite" i.e. the contents of a .test file |
| 38 | """ |
| 39 | p_test_data = Path(test_data_prefix) |
| 40 | p_root = p_test_data.parent.parent |
| 41 | p = p_test_data / f"{data_file_prefix}-meta-{uuid.uuid4()}.test" |
| 42 | assert not p.exists() |
| 43 | data_suite = dedent_docstring(data_suite) |
| 44 | try: |
| 45 | p.write_text(data_suite) |
| 46 | |
| 47 | test_nodeid = f"{pytest_node_prefix}::{p.name}" |
| 48 | extra_args = [sys.executable, "-m", "pytest", "-n", "0", "-s", *extra_args, test_nodeid] |
| 49 | cmd = shlex.join(extra_args) |
| 50 | for i in range(max_attempts - 1, -1, -1): |
| 51 | print(f">> {cmd}") |
| 52 | proc = subprocess.run(extra_args, capture_output=True, check=False, cwd=p_root) |
| 53 | if proc.returncode == 0: |
| 54 | break |
| 55 | prefix = "NESTED PYTEST STDOUT" |
| 56 | for line in proc.stdout.decode().splitlines(): |
| 57 | print(f"{prefix}: {line}") |
| 58 | prefix = " " * len(prefix) |
| 59 | prefix = "NESTED PYTEST STDERR" |
| 60 | for line in proc.stderr.decode().splitlines(): |
| 61 | print(f"{prefix}: {line}") |
| 62 | prefix = " " * len(prefix) |
| 63 | print(f"Exit code {proc.returncode} ({i} attempts remaining)") |
| 64 | |
| 65 | return PytestResult( |
| 66 | input=data_suite, |
| 67 | input_updated=p.read_text(), |
| 68 | stdout=proc.stdout.decode(), |
| 69 | stderr=proc.stderr.decode(), |
| 70 | ) |
| 71 | finally: |
| 72 | p.unlink() |
no test coverage detected
searching dependent graphs…