MCPcopy Index your code
hub / github.com/RustPython/RustPython / remove_testfn

Function remove_testfn

Lib/test/libregrtest/utils.py:480–514  ·  view source on GitHub ↗
(test_name: TestName, verbose: int)

Source from the content-addressed store, hash-verified

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

Callers 1

_load_run_testFunction · 0.85

Calls 5

print_warningFunction · 0.70
existsMethod · 0.45
isdirMethod · 0.45
isfileMethod · 0.45
chmodMethod · 0.45

Tested by

no test coverage detected