Skip to content

Commit 0ead3d6

Browse files
committed
tests: add tests command (bug 1887042)
- remove hardcoding of test paths and move it to pyproject.toml - add management command that runs pytest from project directory - invoke new tests command from GitHub workflow
1 parent 8daf480 commit 0ead3d6

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

.github/workflows/build.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,4 @@ jobs:
4141
source env/bin/activate
4242
lando migrate
4343
lando test
44-
pytest src/lando/api
44+
lando tests

pyproject.toml

+3
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,6 @@ where = ["src"]
3535

3636
[tool.pytest.ini_options]
3737
DJANGO_SETTINGS_MODULE = "lando.test_settings"
38+
testpaths = [
39+
"src/lando/api",
40+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import subprocess
2+
3+
from django.conf import settings
4+
from django.core.management.base import BaseCommand
5+
6+
ROOT_DIR = settings.BASE_DIR.parent.parent
7+
8+
9+
class Command(BaseCommand):
10+
help = "Run pytest from project directory"
11+
12+
def add_arguments(self, parser):
13+
parser.add_argument(
14+
"--exitfirst",
15+
"-x",
16+
action="store_true",
17+
help="Exit instantly on first error or failed test",
18+
)
19+
20+
parser.add_argument(
21+
"paths", nargs="*", type=str, help="Files or directories to pass to pytest"
22+
)
23+
24+
def handle(self, *args, **options):
25+
command = ["pytest"]
26+
27+
if options["exitfirst"]:
28+
command.append("-x")
29+
30+
if options["paths"]:
31+
command += options["paths"]
32+
33+
subprocess.call(command, cwd=ROOT_DIR)

0 commit comments

Comments
 (0)