utils/check-package: add option to run the test-suite

Currently, how to run the check-package test-suite is thoroughly under-
documented. There is one hint in the commit log for commit fc254881e6
(utils/checkpackagelib: add unit tests), and another in commit
242e9d72e7 (utils/docker-run: new script); the former is hard to find,
and the latter is about an unrelated script, so harder yet to find...

Add a new option to check-package, that will make it run its test-suite.
Since pytest is only needed for the test-suite, only import it in that
case.

pytest will be default create a cache of the tests (not sure what it is
about, though), so instruct it not to (esp. since the tree can be
read-only).

Signed-off-by: Yann E. MORIN <yann.morin.1998@free.fr>
Cc: Ricardo Martincoski <ricardo.martincoski@datacom.com.br>
[Arnout: move the code into checkpackagelib.base]
Signed-off-by: Arnout Vandecappelle <arnout@mind.be>
This commit is contained in:
Yann E. MORIN
2024-06-07 19:05:44 +02:00
committed by Arnout Vandecappelle
parent a79adca86f
commit fc2dedcfc6
3 changed files with 16 additions and 0 deletions

View File

@@ -85,6 +85,9 @@ def parse_args():
parser.add_argument("--failed-only", action="store_true", help="print only"
" the name of the functions that failed (debug)")
parser.add_argument("--test-suite", action="store_true", help="Run the"
" test-suite")
flags = parser.parse_args()
flags.ignore_list = get_ignored_parsers_per_file(flags.intree_only, flags.ignore_filename)
@@ -288,6 +291,9 @@ def __main__():
global flags
flags = parse_args()
if flags.test_suite:
return checkpackagelib.base.run_test_suite()
if flags.intree_only:
# change all paths received to be relative to the base dir
base_dir = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))

View File

@@ -1,5 +1,6 @@
# See utils/checkpackagelib/readme.txt before editing this file.
import re
import os
class _CheckFunction(object):
@@ -27,3 +28,11 @@ class _Tool(object):
def hint(self):
return ""
def run_test_suite():
import pytest
return pytest.main(
# Disable writing/loading a cache with: -p no:cacheprovider
["-v", "-p", "no:cacheprovider", os.path.dirname(__file__)]
)

View File

@@ -23,6 +23,7 @@ How the scripts are structured:
- lib_type.py contains check functions specific to files of this type.
Some hints when changing this code:
- test your changes: utils/check-package --test-suite
- prefer O(n) algorithms, where n is the total number of lines in the files
processed.
- when there is no other reason for ordering, use alphabetical order (e.g. keep