File tree Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Original file line number Diff line number Diff line change 6262 log_directory=" "
6363fi
6464
65+ printTask " Testing Python scripts..."
66+ " $REPO_ROOT /test/pyscriptTests.py"
67+
6568printTask " Running commandline tests..."
6669# Only run in parallel if this is run on CI infrastructure
6770if [[ -n " $CI " ]]
Original file line number Diff line number Diff line change 1+ #!/usr/bin/env python
2+
3+ # Runs all tests for Python-based scripts.
4+ # Any Python test suites located in test/scripts/ will executed automatically by this script.
5+
6+ import sys
7+ from pathlib import Path
8+ from unittest import TestLoader , TextTestRunner
9+
10+ SCRIPTS_DIR = Path (__file__ ).parent .parent / "scripts"
11+ TEST_DIR = Path (__file__ ).parent .parent / "test/scripts/"
12+
13+
14+ if __name__ == '__main__' :
15+ # Add the directory containing scripts to be tested to PYTHONPATH. This means that these
16+ # scripts can be imported from anywhere (in particular from the test suites) as if they were
17+ # installed globally. This is necessary because scripts and their tests are in separate
18+ # directories not recognized by Python as a part of the same package (i.e. their common parent
19+ # directory does not have an __init__.py file).
20+ # NOTE: This does not play well with relative imports from test suites so the suites must be
21+ # placed directly in TEST_DIR and not in its subdirectories. Relative imports from scripts
22+ # themselves work fine though.
23+ sys .path .insert (0 , str (SCRIPTS_DIR ))
24+
25+ # This is equivalent to `python -m unittest discover --start-directory $TEST_DIR`
26+ test_suite = TestLoader ().discover (start_dir = TEST_DIR )
27+ result = TextTestRunner ().run (test_suite )
28+
29+ if len (result .errors ) > 0 or len (result .failures ) > 0 :
30+ sys .exit (1 )
You can’t perform that action at this time.
0 commit comments