-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
runtests.py
85 lines (68 loc) · 2.96 KB
/
runtests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# -*- coding: utf-8 -*-
#
# Copyright © Spyder Project Contributors
# Licensed under the terms of the MIT License
#
"""
Script for running Spyder tests programmatically.
"""
# Standard library imports
import argparse
import os
# To activate/deactivate certain things for pytests only
# NOTE: Please leave this before any other import here!!
os.environ['SPYDER_PYTEST'] = 'True'
# Third party imports
# NOTE: This needs to be imported before any QApplication.
# Don't remove it or change it to a different location!
# pylint: disable=wrong-import-position
from qtpy import QtWebEngineWidgets # noqa
import pytest
# To run our slow tests only in our CIs
CI = bool(os.environ.get('CI', None))
RUN_SLOW = os.environ.get('RUN_SLOW', None) == 'true'
def run_pytest(run_slow=False, extra_args=None, remoteclient=False):
"""Run pytest tests for Spyder."""
# Be sure to ignore subrepos and remoteclient plugin
pytest_args = ['-vv', '-rw', '--durations=10', '--ignore=./external-deps',
'-W ignore::UserWarning', '--timeout=120',
'--timeout_method=thread']
if CI:
# Show coverage
pytest_args += ['--cov=spyder', '--no-cov-on-fail', '--cov-report=xml']
# To display nice tests resume in Azure's web page
if os.environ.get('AZURE', None) is not None:
pytest_args += ['--cache-clear', '--junitxml=result.xml']
if run_slow or RUN_SLOW:
pytest_args += ['--run-slow']
# Allow user to pass a custom test path to pytest to e.g. run just one test
if extra_args:
pytest_args += extra_args
if remoteclient:
pytest_args += ['--container-scope=class',
'./spyder/plugins/remoteclient']
os.environ["SPYDER_TEST_REMOTE_CLIENT"] = "true"
else:
pytest_args += ['--ignore=./spyder/plugins/remoteclient']
print("Pytest Arguments: " + str(pytest_args))
errno = pytest.main(pytest_args)
# sys.exit doesn't work here because some things could be running in the
# background (e.g. closing the main window) when this point is reached.
# If that's the case, sys.exit doesn't stop the script as you would expect.
if errno != 0:
raise SystemExit(errno)
def main():
"""Parse args then run the pytest suite for Spyder."""
test_parser = argparse.ArgumentParser(
usage=('python runtests.py'
'[-h] [--run-slow] [--remote-client] [pytest_args]'),
description="Helper script to run Spyder's test suite")
test_parser.add_argument('--run-slow', action='store_true', default=False,
help='Run the slow tests')
test_parser.add_argument("--remote-client", action="store_true",
default=False, help="Run the remote client tests")
test_args, pytest_args = test_parser.parse_known_args()
run_pytest(run_slow=test_args.run_slow, extra_args=pytest_args,
remoteclient=test_args.remote_client)
if __name__ == '__main__':
main()