1#!/usr/bin/env python3
2
3# Copyright (c) 2020 Nordic Semiconductor ASA
4#
5# SPDX-License-Identifier: Apache-2.0
6
7# A convenience script provided for running tests on the runners
8# package. Runs mypy and pytest. Any extra arguments in sys.argv are
9# passed along to pytest.
10#
11# Using tox was considered, but rejected as overkill for now.
12#
13# We would have to configure tox to create the test virtualenv with
14# all of zephyr's scripts/requirements.txt, which seems like too much
15# effort for now. We just run in the same Python environment as the
16# user for developer testing and trust CI to set that environment up
17# properly for integration testing.
18#
19# If this file starts to reimplement too many features that are
20# already available in tox, we can revisit this decision.
21
22import os
23import shlex
24import subprocess
25import sys
26
27here = os.path.abspath(os.path.dirname(__file__))
28
29mypy = [sys.executable, '-m', 'mypy', f'--config-file={here}/mypy.ini',
30        '--package', 'runners']
31pytest = [sys.executable, '-m', 'pytest'] + sys.argv[1:]
32
33print(f'Running mypy from {here}:\n\t' +
34      ' '.join(shlex.quote(s) for s in mypy),
35      flush=True)
36subprocess.run(mypy, check=True, cwd=here)
37print(f'Running pytest from {here}:\n\t' +
38      ' '.join(shlex.quote(s) for s in pytest),
39      flush=True)
40subprocess.run(pytest, check=True, cwd=here)
41