xonsh/run-tests.xsh
Noorhteen Raja NJ 38295a1dd9
Remove globals (#4280)
* refactor: remove usage of global variables in abbrevs.py

* chore: add flake8-mutable to prevent mutable defaults

* fix: abbrevs expand test

* refactor: add xonsh session singleton

* refactor: fix circular errors when using xonshSession as singleton

* refactor: remove black magicked builtin attributes

* style: black format tests as well

* refactor: update tests to use xonsh-session singleton

* refactor: update abbrevs to not use builtins

* test: remove DummyCommandsCache and patch orig class

* fix: failing test_command_completers

* test: use monkeypatch to update xession fixture

* fix: failing test_pipelines

* fix: failing test_main

* chore: run test suit as single invocation

* test: fix tests/test_xonsh.xsh

* refactor: remove builtins from docs/conf.py

* fix: mypy error in jobs

* fix: test error from test_main

* test: close xession error in test_command_completers

* chore: use pytest-cov for reporting coverage

this will include subprocess calls, and will increase coverage

* style:
2021-05-20 13:14:26 +03:00

78 lines
1.9 KiB
Python
Executable file

#!/usr/bin/env xonsh
import argparse
import subprocess
from typing import List
$XONSH_DEBUG = 1
$RAISE_SUBPROC_ERROR = True
# $XONSH_TRACE_SUBPROC = True
def _replace_args(args: List[str], num: int) -> List[str]:
return [
(arg % num) if "%d" in arg else arg
for arg in args
]
def test(ns: argparse.Namespace):
"""Run pytest.
Examples
--------
`xonsh run-tests.xsh -- --junitxml=junit/test-results.%%d.xml`
"""
args = ns.pytest_args
if ns.report_coverage:
![pytest @(_replace_args(args, 0)) --cov --cov-report=xml --cov-report=term]
else:
![pytest @(_replace_args(args, 0))]
def qa(ns: argparse.Namespace):
"""QA checks"""
echo "---------- Check Black formatter -----------"
black --check xonsh xontrib tests
echo "---------- Running flake8 ----------"
python -m flake8
echo "---------- Running mypy ----------"
mypy --version
# todo: add xontrib folder here
mypy xonsh --exclude xonsh/ply
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.set_defaults(func=lambda *args: parser.print_help())
commands = parser.add_subparsers()
test_parser = commands.add_parser('test', help=test.__doc__)
test_parser.add_argument(
'pytest_args',
nargs='*',
help="arbitrary arguments that gets passed to pytest's invocation."
" Use %%d to parameterize and prevent overwrite "
)
test_parser.add_argument(
'--report-coverage',
action="store_true",
default=False,
help="Report coverage at the end of the test",
)
test_parser.set_defaults(func=test)
qa_parser = commands.add_parser('qa', help=qa.__doc__)
qa_parser.set_defaults(func=qa)
args = parser.parse_args()
try:
args.func(args)
except subprocess.CalledProcessError as ex:
parser.exit(1, f"Failed with {ex}")