| 309 | self.tmpdir: str | None = None |
| 310 | |
| 311 | def runtest(self) -> None: |
| 312 | if self.skip: |
| 313 | pytest.skip() |
| 314 | # TODO: add a better error message for when someone uses skip and xfail at the same time |
| 315 | elif self.xfail: |
| 316 | self.add_marker(pytest.mark.xfail) |
| 317 | |
| 318 | if ( |
| 319 | not [line for line in self.input if line.strip()] |
| 320 | and "Empty" not in self.name |
| 321 | and not [ |
| 322 | file |
| 323 | for file in self.files |
| 324 | # these files are added based on other things |
| 325 | if os.path.basename(file[0]) not in ("typing.pyi", "_typeshed.pyi", "builtins.pyi") |
| 326 | ] |
| 327 | ): |
| 328 | raise AssertionError(f"{self.name} is empty.") |
| 329 | |
| 330 | parent = self.getparent(DataSuiteCollector) |
| 331 | assert parent is not None, "Should not happen" |
| 332 | suite = parent.obj() |
| 333 | suite.setup() |
| 334 | try: |
| 335 | suite.run_case(self) |
| 336 | except Exception: |
| 337 | # As a debugging aid, support copying the contents of the tmp directory somewhere |
| 338 | save_dir: str | None = self.config.getoption("--save-failures-to", None) |
| 339 | if save_dir: |
| 340 | assert self.tmpdir is not None |
| 341 | target_dir = os.path.join(save_dir, os.path.basename(self.tmpdir)) |
| 342 | print(f"Copying data from test {self.name} to {target_dir}") |
| 343 | if not os.path.isabs(target_dir): |
| 344 | assert self.old_cwd |
| 345 | target_dir = os.path.join(self.old_cwd, target_dir) |
| 346 | shutil.copytree(self.tmpdir, target_dir) |
| 347 | raise |
| 348 | |
| 349 | def setup(self) -> None: |
| 350 | parse_test_case(case=self) |