|
9 | 9 | TEST_DATA_PATH = pathlib.Path(__file__).parent / ".data" |
10 | 10 |
|
11 | 11 |
|
| 12 | +def find_class_line_number(class_name: str, test_file_path) -> str: |
| 13 | + """Function which finds the correct line number for a class definition. |
| 14 | +
|
| 15 | + Args: |
| 16 | + class_name: The name of the class to find the line number for. |
| 17 | + test_file_path: The path to the test file where the class is located. |
| 18 | + """ |
| 19 | + # Look for the class definition line |
| 20 | + with pathlib.Path(test_file_path).open() as f: |
| 21 | + for i, line in enumerate(f): |
| 22 | + # Match "class ClassName" or "class ClassName(" or "class ClassName:" |
| 23 | + if line.strip().startswith(f"class {class_name}") or line.strip().startswith( |
| 24 | + f"class {class_name}(" |
| 25 | + ): |
| 26 | + return str(i + 1) |
| 27 | + error_str: str = f"Class {class_name!r} not found on any line in {test_file_path}" |
| 28 | + raise ValueError(error_str) |
| 29 | + |
| 30 | + |
12 | 31 | skip_unittest_folder_discovery_output = { |
13 | 32 | "path": os.fspath(TEST_DATA_PATH / "unittest_skip"), |
14 | 33 | "name": "unittest_skip", |
|
49 | 68 | ], |
50 | 69 | "id_": os.fspath(TEST_DATA_PATH / "unittest_skip" / "unittest_skip_function.py") |
51 | 70 | + "\\SimpleTest", |
| 71 | + "lineno": find_class_line_number( |
| 72 | + "SimpleTest", |
| 73 | + TEST_DATA_PATH / "unittest_skip" / "unittest_skip_function.py", |
| 74 | + ), |
52 | 75 | } |
53 | 76 | ], |
54 | 77 | "id_": os.fspath(TEST_DATA_PATH / "unittest_skip" / "unittest_skip_function.py"), |
|
114 | 137 | }, |
115 | 138 | ], |
116 | 139 | "id_": complex_tree_file_path + "\\" + "TreeOne", |
| 140 | + "lineno": find_class_line_number( |
| 141 | + "TreeOne", |
| 142 | + pathlib.PurePath( |
| 143 | + TEST_DATA_PATH, |
| 144 | + "utils_complex_tree", |
| 145 | + "test_outer_folder", |
| 146 | + "test_inner_folder", |
| 147 | + "test_utils_complex_tree.py", |
| 148 | + ), |
| 149 | + ), |
117 | 150 | } |
118 | 151 | ], |
119 | 152 | "id_": complex_tree_file_path, |
|
0 commit comments