Parse and prepare a single case from suite with test case descriptions. This method is part of the setup phase, just before the test case is run.
(case: DataDrivenTestCase)
| 54 | |
| 55 | |
| 56 | def parse_test_case(case: DataDrivenTestCase) -> None: |
| 57 | """Parse and prepare a single case from suite with test case descriptions. |
| 58 | |
| 59 | This method is part of the setup phase, just before the test case is run. |
| 60 | """ |
| 61 | test_items = parse_test_data(case.data, case.name) |
| 62 | base_path = case.suite.base_path |
| 63 | if case.suite.native_sep: |
| 64 | join = os.path.join |
| 65 | else: |
| 66 | join = posixpath.join |
| 67 | |
| 68 | out_section_missing = case.suite.required_out_section |
| 69 | |
| 70 | files: list[tuple[str, str]] = [] # path and contents |
| 71 | output_files: list[tuple[str, str | Pattern[str]]] = [] # output path and contents |
| 72 | output: list[str] = [] # Regular output errors |
| 73 | output2: dict[int, list[str]] = {} # Output errors for incremental, runs 2+ |
| 74 | deleted_paths: dict[int, set[str]] = {} # from run number of paths |
| 75 | stale_modules: dict[int, set[str]] = {} # from run number to module names |
| 76 | rechecked_modules: dict[int, set[str]] = {} # from run number module names |
| 77 | triggered: list[str] = [] # Active triggers (one line per incremental step) |
| 78 | targets: dict[int, list[str]] = {} # Fine-grained targets (per fine-grained update) |
| 79 | test_modules: list[str] = [] # Modules which are deemed "test" (vs "fixture") |
| 80 | |
| 81 | def _case_fail(msg: str) -> NoReturn: |
| 82 | pytest.fail(f"{case.file}:{case.line}: {msg}", pytrace=False) |
| 83 | |
| 84 | # Process the parsed items. Each item has a header of form [id args], |
| 85 | # optionally followed by lines of text. |
| 86 | item = first_item = test_items[0] |
| 87 | test_modules.append("__main__") |
| 88 | for item in test_items[1:]: |
| 89 | |
| 90 | def _item_fail(msg: str) -> NoReturn: |
| 91 | item_abs_line = case.line + item.line - 2 |
| 92 | pytest.fail(f"{case.file}:{item_abs_line}: {msg}", pytrace=False) |
| 93 | |
| 94 | if item.id in {"file", "fixture", "outfile", "outfile-re"}: |
| 95 | # Record an extra file needed for the test case. |
| 96 | assert item.arg is not None |
| 97 | contents = expand_variables("\n".join(item.data)) |
| 98 | path = join(base_path, item.arg) |
| 99 | if item.id != "fixture": |
| 100 | test_modules.append(_file_arg_to_module(item.arg)) |
| 101 | if item.id in {"file", "fixture"}: |
| 102 | files.append((path, contents)) |
| 103 | elif item.id == "outfile-re": |
| 104 | output_files.append((path, re.compile(contents.rstrip(), re.S))) |
| 105 | elif item.id == "outfile": |
| 106 | output_files.append((path, contents)) |
| 107 | elif item.id == "builtins": |
| 108 | # Use an alternative stub file for the builtins module. |
| 109 | assert item.arg is not None |
| 110 | mpath = join(os.path.dirname(case.file), item.arg) |
| 111 | with open(mpath, encoding="utf8") as f: |
| 112 | files.append((join(base_path, "builtins.pyi"), f.read())) |
| 113 | elif item.id == "typing": |
no test coverage detected
searching dependent graphs…