Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: add tests management command (bug 1887042) #52

Merged
merged 1 commit into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ jobs:
source env/bin/activate
lando migrate
lando test
pytest src/lando/api
lando tests
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,6 @@ where = ["src"]

[tool.pytest.ini_options]
DJANGO_SETTINGS_MODULE = "lando.test_settings"
testpaths = [
"src/lando/api",
]
33 changes: 33 additions & 0 deletions src/lando/utils/management/commands/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import subprocess

from django.conf import settings
from django.core.management.base import BaseCommand

ROOT_DIR = settings.BASE_DIR.parent.parent


class Command(BaseCommand):
help = "Run pytest from project directory"

def add_arguments(self, parser):
parser.add_argument(
"--exitfirst",
"-x",
action="store_true",
help="Exit instantly on first error or failed test",
)

parser.add_argument(
"paths", nargs="*", type=str, help="Files or directories to pass to pytest"
)

def handle(self, *args, **options):
command = ["pytest"]

if options["exitfirst"]:
command.append("-x")

if options["paths"]:
command += options["paths"]

subprocess.call(command, cwd=ROOT_DIR)
Loading