diff --git a/README.rst b/README.rst index 7052250..1e89c72 100644 --- a/README.rst +++ b/README.rst @@ -5,14 +5,14 @@ ttrun Simple CLI to run testtools tests In a `testrepository` based workflow, sometimes you want/need to run individual -tests. Additionally, someitmes you want to use a pre-existing tox virtualenv +tests. Additionally, someitmes you want to use a pre-existing tox or nox virtualenv to do so. Or, at least, I do. Typing .. code-block:: bash - .tox/py27/bin/python -m testtools.run some.test + .nox/py27/bin/python -m testtools.run some.test Got boring. So this is a simple wrapper. @@ -24,12 +24,12 @@ It has two modes. Will run that test with the system python. -If you want to re-use a tox virtualenv. +If you want to re-use a nox virtualenv. .. code-block:: bash ttrun -epy27 some.test -Will run some.test in the given tox venv. +Will run some.test in the given nox venv. Both modes can be run with no parameters to have testtools run all the tests. diff --git a/ttrun/cmd.py b/ttrun/cmd.py index 41ab799..123f91e 100644 --- a/ttrun/cmd.py +++ b/ttrun/cmd.py @@ -16,6 +16,7 @@ # along with Ansible. If not, see . import argparse +import os import subprocess import sys @@ -35,14 +36,14 @@ def main(): args = parse_arguments() if args.environment: - return subprocess.call( - [ - ".tox/{environment}/bin/python".format(environment=args.environment), - "-m", - "testtools.run", - ] - + args.tests - ) + python_path = f".nox/{args.environment}/bin/python" + if not os.path.exists(python_path): + python_path = f".tox/{args.environment}/bin/python" + if not os.path.exists(python_path): + raise RuntimeError( + f"{args.environment} does not exist. Have you created it yet?" + ) + return subprocess.call([python_path, "-m", "testtools.run"] + args.tests) else: return testtools.run.main([sys.argv[0]] + args.tests, sys.stdout)