Testing - pytest
Write and run tests with pytest.
Django includes its own test runner and unittest classes. But a lot of people (myself included) prefer pytest.
In Plain I've removed the Django test runner and a lot of the implications that come with it.
There are a few utilities that remain to make testing easier,
and plain-test
is a wrapper around pytest
.
1import os
2import sys
3
4import click
5from dotenv import load_dotenv
6
7import pytest
8
9
10@click.command(
11 context_settings={
12 "ignore_unknown_options": True,
13 }
14)
15@click.argument("pytest_args", nargs=-1, type=click.UNPROCESSED)
16def cli(pytest_args):
17 """Run tests with pytest"""
18
19 if os.path.exists(".env.test"):
20 click.secho("Loading environment variables from .env.test", fg="yellow")
21 load_dotenv(".env.test")
22
23 returncode = pytest.main(list(pytest_args))
24 if returncode:
25 sys.exit(returncode)