zephyr/scripts/west_commands/run_tests.py
Martí Bolívar bd827056f6 scripts: runners: add type checking for west_commands
Use mypy to type check the runners package.

The test procedure is now annoying enough to replicate locally that
I'm going to wrap it in a script. Do this for both UNIX and Windows
environments by writing that script in Python.

Keep the GitHub workflow up to date so we now get mypy results in CI.

Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2020-09-03 16:49:09 -05:00

41 lines
1.3 KiB
Python
Executable file

#!/usr/bin/env python3
# Copyright (c) 2020 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: Apache-2.0
# A convenience script provided for running tests on the runners
# package. Runs mypy and pytest. Any extra arguments in sys.argv are
# passed along to pytest.
#
# Using tox was considered, but rejected as overkill for now.
#
# We would have to configure tox to create the test virtualenv with
# all of zephyr's scripts/requirements.txt, which seems like too much
# effort for now. We just run in the same Python environment as the
# user for developer testing and trust CI to set that environment up
# properly for integration testing.
#
# If this file starts to reimplement too many features that are
# already available in tox, we can revisit this decision.
import os
import shlex
import subprocess
import sys
here = os.path.abspath(os.path.dirname(__file__))
mypy = [sys.executable, '-m', 'mypy', f'--config-file={here}/mypy.ini',
'--package', 'runners']
pytest = [sys.executable, '-m', 'pytest'] + sys.argv[1:]
print(f'Running mypy from {here}:\n\t' +
' '.join(shlex.quote(s) for s in mypy),
flush=True)
subprocess.run(mypy, check=True, cwd=here)
print(f'Running pytest from {here}:\n\t' +
' '.join(shlex.quote(s) for s in pytest),
flush=True)
subprocess.run(pytest, check=True, cwd=here)