hassle.run_tests

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

Run tests with coverage and pytest.

def main(args: argparse.Namespace = None):
37def main(args: argparse.Namespace = None):
38    if not args:
39        args = get_args()
40    package_path = Pathier(args.package_name).resolve()
41    run_tests(package_path)