(test_name: TestName, verbose: int)
| 491 | |
| 492 | |
| 493 | def remove_testfn(test_name: TestName, verbose: int) -> None: |
| 494 | # Try to clean up os_helper.TESTFN if left behind. |
| 495 | # |
| 496 | # While tests shouldn't leave any files or directories behind, when a test |
| 497 | # fails that can be tedious for it to arrange. The consequences can be |
| 498 | # especially nasty on Windows, since if a test leaves a file open, it |
| 499 | # cannot be deleted by name (while there's nothing we can do about that |
| 500 | # here either, we can display the name of the offending test, which is a |
| 501 | # real help). |
| 502 | name = os_helper.TESTFN |
| 503 | if not os.path.exists(name): |
| 504 | return |
| 505 | |
| 506 | nuker: Callable[[str], None] |
| 507 | if os.path.isdir(name): |
| 508 | import shutil |
| 509 | kind, nuker = "directory", shutil.rmtree |
| 510 | elif os.path.isfile(name): |
| 511 | kind, nuker = "file", os.unlink |
| 512 | else: |
| 513 | raise RuntimeError(f"os.path says {name!r} exists but is neither " |
| 514 | f"directory nor file") |
| 515 | |
| 516 | if verbose: |
| 517 | print_warning(f"{test_name} left behind {kind} {name!r}") |
| 518 | support.environment_altered = True |
| 519 | |
| 520 | try: |
| 521 | import stat |
| 522 | # fix possible permissions problems that might prevent cleanup |
| 523 | os.chmod(name, stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO) |
| 524 | nuker(name) |
| 525 | except Exception as exc: |
| 526 | print_warning(f"{test_name} left behind {kind} {name!r} " |
| 527 | f"and it couldn't be removed: {exc}") |
| 528 | |
| 529 | |
| 530 | def abs_module_name(test_name: TestName, test_dir: StrPath | None) -> TestName: |
no test coverage detected
searching dependent graphs…