Browse Source

Add test filter to 'qmk pytest' (#15432)

* Add test filter to 'qmk pytest'

* Bodge for some test filters not resolving qmk

* Update docs
Joel Challis 4 years ago
parent
commit
aecb387692
2 changed files with 18 additions and 2 deletions
  1. 16 1
      docs/cli_commands.md
  2. 2 1
      lib/python/qmk/cli/pytest.py

+ 16 - 1
docs/cli_commands.md

@@ -481,5 +481,20 @@ This command runs the python test suite. If you make changes to python code you
 **Usage**:
 
 ```
-qmk pytest
+qmk pytest [-t TEST]
 ```
+
+**Examples**:
+
+Run entire test suite:
+
+    qmk pytest
+
+Run test group:
+
+    qmk pytest -t qmk.tests.test_cli_commands
+
+Run single test:
+
+    qmk pytest -t qmk.tests.test_cli_commands.test_c2json
+    qmk pytest -t qmk.tests.test_qmk_path

+ 2 - 1
lib/python/qmk/cli/pytest.py

@@ -7,11 +7,12 @@ from subprocess import DEVNULL
 from milc import cli
 
 
+@cli.argument('-t', '--test', arg_only=True, action='append', default=[], help="Mapped to nose2 'testNames' positional argument - https://docs.nose2.io/en/latest/usage.html#specifying-tests-to-run")
 @cli.subcommand('QMK Python Unit Tests', hidden=False if cli.config.user.developer else True)
 def pytest(cli):
     """Run several linting/testing commands.
     """
-    nose2 = cli.run(['nose2', '-v'], capture_output=False, stdin=DEVNULL)
+    nose2 = cli.run(['nose2', '-v', '-t' 'lib/python', *cli.args.test], capture_output=False, stdin=DEVNULL)
     flake8 = cli.run(['flake8', 'lib/python'], capture_output=False, stdin=DEVNULL)
 
     return flake8.returncode | nose2.returncode