Add support for nox dirs

We use nox in a lot of places now. We should support that.

Change-Id: I21a592b4cea3e4acc7540f00504322c7e6a6edb8
This commit is contained in:
Monty Taylor 2024-06-02 11:41:05 +02:00
parent 3df738d481
commit f9bc46226c
2 changed files with 13 additions and 12 deletions

View File

@ -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.

View File

@ -16,6 +16,7 @@
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
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)