Merge pull request #10819 from ethereum/python-unit-tests-in-ci

CI job for running Python unit tests
This commit is contained in:
Kamil Śliwak 2021-01-22 15:30:31 +01:00 committed by GitHub
commit aef724cc2f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 55 additions and 0 deletions

View File

@ -414,6 +414,26 @@ jobs:
- checkout
- run: *run_docs_pragma_min_version
t_pyscripts_ubu:
docker:
- image: << pipeline.parameters.ubuntu-2004-docker-image >>
steps:
- checkout
- run:
name: Python unit tests
command: python3 test/pyscriptTests.py
t_pyscripts_win:
executor:
name: win/default
shell: powershell.exe
steps:
- run: git config --global core.autocrlf false
- checkout
- run:
name: Python unit tests
command: python.exe test/pyscriptTests.py
b_ubu_clang: &build_ubuntu2004_clang
resource_class: xlarge
docker:
@ -991,6 +1011,8 @@ workflows:
- chk_errorcodes: *workflow_trigger_on_tags
- chk_antlr_grammar: *workflow_trigger_on_tags
- chk_docs_pragma_min_version: *workflow_trigger_on_tags
- t_pyscripts_ubu: *workflow_trigger_on_tags
- t_pyscripts_win: *workflow_trigger_on_tags
# build-only
- b_docs: *workflow_trigger_on_tags

View File

@ -62,6 +62,9 @@ else
log_directory=""
fi
printTask "Testing Python scripts..."
"$REPO_ROOT/test/pyscriptTests.py"
printTask "Running commandline tests..."
# Only run in parallel if this is run on CI infrastructure
if [[ -n "$CI" ]]

30
test/pyscriptTests.py Executable file
View File

@ -0,0 +1,30 @@
#!/usr/bin/env python3
# Runs all tests for Python-based scripts.
# Any Python test suites located in test/scripts/ will be executed automatically by this script.
import sys
from pathlib import Path
from unittest import TestLoader, TextTestRunner
SCRIPTS_DIR = Path(__file__).parent.parent / "scripts"
TEST_DIR = Path(__file__).parent.parent / "test/scripts/"
if __name__ == '__main__':
# Add the directory containing scripts to be tested to PYTHONPATH. This means that these
# scripts can be imported from anywhere (in particular from the test suites) as if they were
# installed globally. This is necessary because scripts and their tests are in separate
# directories not recognized by Python as a part of the same package (i.e. their common parent
# directory does not have an __init__.py file).
# NOTE: This does not play well with relative imports from test suites so the suites must be
# placed directly in TEST_DIR and not in its subdirectories. Relative imports from scripts
# themselves work fine though.
sys.path.insert(0, str(SCRIPTS_DIR))
# This is equivalent to `python -m unittest discover --start-directory $TEST_DIR`
test_suite = TestLoader().discover(start_dir=TEST_DIR)
result = TextTestRunner().run(test_suite)
if len(result.errors) > 0 or len(result.failures) > 0:
sys.exit(1)