Iterate over raw test cases in file, at collection time, ignoring sub items. The collection phase is slow, so any heavy processing should be deferred to after uninteresting tests are filtered (when using -k PATTERN switch).
(
parent: DataFileCollector, suite: DataSuite, file: str
)
| 683 | |
| 684 | |
| 685 | def split_test_cases( |
| 686 | parent: DataFileCollector, suite: DataSuite, file: str |
| 687 | ) -> Iterator[DataDrivenTestCase]: |
| 688 | """Iterate over raw test cases in file, at collection time, ignoring sub items. |
| 689 | |
| 690 | The collection phase is slow, so any heavy processing should be deferred to after |
| 691 | uninteresting tests are filtered (when using -k PATTERN switch). |
| 692 | """ |
| 693 | with open(file, encoding="utf-8") as f: |
| 694 | data = f.read() |
| 695 | cases = re.split(r"^\[case ([^]+)]+)\][ \t]*$\n", data, flags=re.DOTALL | re.MULTILINE) |
| 696 | cases_iter = iter(cases) |
| 697 | line_no = next(cases_iter).count("\n") + 1 |
| 698 | test_names = set() |
| 699 | for case_id in cases_iter: |
| 700 | data = next(cases_iter) |
| 701 | |
| 702 | m = _case_name_pattern.fullmatch(case_id) |
| 703 | if not m: |
| 704 | raise RuntimeError(f"Invalid testcase id {case_id!r}") |
| 705 | name = m.group("name") |
| 706 | if name in test_names: |
| 707 | raise RuntimeError( |
| 708 | 'Found a duplicate test name "{}" in {} on line {}'.format( |
| 709 | name, parent.name, line_no |
| 710 | ) |
| 711 | ) |
| 712 | yield DataDrivenTestCase.from_parent( |
| 713 | parent=parent, |
| 714 | suite=suite, |
| 715 | file=file, |
| 716 | name=add_test_name_suffix(name, suite.test_name_suffix), |
| 717 | writescache=bool(m.group("writescache")), |
| 718 | only_when=m.group("only_when"), |
| 719 | platform=m.group("platform"), |
| 720 | skip=bool(m.group("skip")), |
| 721 | xfail=bool(m.group("xfail")), |
| 722 | normalize_output=not m.group("skip_path_normalization"), |
| 723 | data=data, |
| 724 | line=line_no, |
| 725 | ) |
| 726 | line_no += data.count("\n") + 1 |
| 727 | |
| 728 | # Record existing tests to prevent duplicates: |
| 729 | test_names.update({name}) |
| 730 | |
| 731 | |
| 732 | class DataSuiteCollector(pytest.Class): |
no test coverage detected
searching dependent graphs…