Browse Source

Add invoke task to run tests

This way, instead of needing to know that you run "pytest" and knowing
tricks like "pytest -m ''" to run webtests and HTML validation, you can
now just run "invoke test", with more intuitive flags. This also reduces
the output in quiet mode even more.

After adding invoke tasks for some of the other tools/checks, I'll be
able to switch the git hooks to use these instead.
merge-requests/135/head
Deimos 4 years ago
parent
commit
c2bfe2e2c7
  1. 2
      tildes/pytest.ini
  2. 47
      tildes/tasks.py

2
tildes/pytest.ini

@ -1,6 +1,6 @@
[pytest]
testpaths = tests
addopts = -p no:cacheprovider --strict-markers -m "not (html_validation or webtest)"
addopts = -p no:cacheprovider --strict-markers
filterwarnings =
ignore::DeprecationWarning
ignore::PendingDeprecationWarning

47
tildes/tasks.py

@ -9,6 +9,53 @@ from pathlib import Path
from invoke import task
def output(string):
"""Output a string without a line ending and flush immediately."""
print(string, end="", flush=True)
@task(
help={
"html-validation": "Include HTML validation (very slow, includes webtests)",
"quiet": "Reduce verbosity",
"webtests": "Include webtests (a little slow)",
}
)
def test(context, quiet=False, webtests=False, html_validation=False):
"""Run the tests.
By default, webtests (ones that make actual HTTP requests to the app) and HTML
validation tests (checking the validity of the HTML on some of the site's pages) are
not run because they are slow, but you can include them with the appropriate flag.
"""
# webtests are required as part of HTML validation
if html_validation:
webtests = True
pytest_args = []
excluded_markers = []
if not webtests:
excluded_markers.append("webtest")
if not html_validation:
excluded_markers.append("html_validation")
if excluded_markers:
excluded_marker_str = " or ".join(excluded_markers)
pytest_args.append(f'-m "not ({excluded_marker_str})"')
if quiet:
output("Running tests... ")
pytest_args.append("-q")
result = context.run("pytest " + " ".join(pytest_args), hide=True)
# only output the final line of pytest's stdout (test count + runtime)
print(result.stdout.splitlines()[-1])
else:
context.run("pytest " + " ".join(pytest_args), pty=True)
@task
def update_pip_requirements(context):
"""Use pip-tools to update package versions in the requirements files."""

Loading…
Cancel
Save