hassle.run_tests
1import argparse 2import os 3from pathlib import Path 4 5 6def get_args() -> argparse.Namespace: 7 parser = argparse.ArgumentParser() 8 9 parser.add_argument( 10 "package_name", 11 type=str, 12 default=".", 13 nargs="?", 14 help=""" The name of the package or project to run tests for, 15 assuming it's a subfolder of your current working directory. 16 Can also be a full path to the package. If nothing is given, 17 the current working directory will be used.""", 18 ) 19 20 args = parser.parse_args() 21 22 return args 23 24 25def run_tests(package_path: Path): 26 """Run tests with coverage and pytest.""" 27 startdir = Path().cwd() 28 os.chdir(package_path) 29 os.system(f"coverage run -m pytest -s") 30 os.system(f"coverage report -m") 31 os.chdir(startdir) 32 33 34def main(args: argparse.Namespace = None): 35 if not args: 36 args = get_args() 37 package_path = Path(args.package_name).resolve() 38 run_tests(package_path) 39 40 41if __name__ == "__main__": 42 main(get_args())
def
get_args() -> argparse.Namespace:
7def get_args() -> argparse.Namespace: 8 parser = argparse.ArgumentParser() 9 10 parser.add_argument( 11 "package_name", 12 type=str, 13 default=".", 14 nargs="?", 15 help=""" The name of the package or project to run tests for, 16 assuming it's a subfolder of your current working directory. 17 Can also be a full path to the package. If nothing is given, 18 the current working directory will be used.""", 19 ) 20 21 args = parser.parse_args() 22 23 return args
def
run_tests(package_path: pathlib.Path):
26def run_tests(package_path: Path): 27 """Run tests with coverage and pytest.""" 28 startdir = Path().cwd() 29 os.chdir(package_path) 30 os.system(f"coverage run -m pytest -s") 31 os.system(f"coverage report -m") 32 os.chdir(startdir)
Run tests with coverage and pytest.
def
main(args: argparse.Namespace = None):