test(backend): switch to django test runner
This commit is contained in:
11
.coveragerc
Normal file
11
.coveragerc
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
[run]
|
||||||
|
branch = True
|
||||||
|
source =
|
||||||
|
apps
|
||||||
|
omit =
|
||||||
|
*/migrations/*
|
||||||
|
*/tests/*
|
||||||
|
|
||||||
|
[report]
|
||||||
|
show_missing = True
|
||||||
|
skip_covered = False
|
||||||
1
apps/notifications/tests/__init__.py
Normal file
1
apps/notifications/tests/__init__.py
Normal file
@@ -0,0 +1 @@
|
|||||||
|
|
||||||
1
apps/time_entries/tests/__init__.py
Normal file
1
apps/time_entries/tests/__init__.py
Normal file
@@ -0,0 +1 @@
|
|||||||
|
|
||||||
1
apps/users/tests/__init__.py
Normal file
1
apps/users/tests/__init__.py
Normal file
@@ -0,0 +1 @@
|
|||||||
|
|
||||||
@@ -28,3 +28,4 @@ CELERY_TASK_ALWAYS_EAGER = True
|
|||||||
CELERY_TASK_EAGER_PROPAGATES = True
|
CELERY_TASK_EAGER_PROPAGATES = True
|
||||||
|
|
||||||
EMAIL_BACKEND = "django.core.mail.backends.locmem.EmailBackend"
|
EMAIL_BACKEND = "django.core.mail.backends.locmem.EmailBackend"
|
||||||
|
TEST_RUNNER = "config.test_runner.AppDiscoverRunner"
|
||||||
|
|||||||
51
config/test_runner.py
Normal file
51
config/test_runner.py
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
from django.apps import apps
|
||||||
|
from django.test.runner import DiscoverRunner
|
||||||
|
|
||||||
|
|
||||||
|
class AppDiscoverRunner(DiscoverRunner):
|
||||||
|
def load_tests_for_label(self, label, discover_kwargs):
|
||||||
|
if label.startswith("apps."):
|
||||||
|
try:
|
||||||
|
app_config = apps.get_app_config(label.split(".", 1)[1])
|
||||||
|
except LookupError:
|
||||||
|
return super().load_tests_for_label(label, discover_kwargs)
|
||||||
|
|
||||||
|
test_dir = Path(app_config.path) / "tests"
|
||||||
|
if test_dir.exists():
|
||||||
|
repo_root = Path(__file__).resolve().parent.parent
|
||||||
|
discover_kwargs = dict(discover_kwargs)
|
||||||
|
discover_kwargs["top_level_dir"] = str(repo_root)
|
||||||
|
return self.test_loader.discover(
|
||||||
|
start_dir=str(test_dir),
|
||||||
|
**discover_kwargs,
|
||||||
|
)
|
||||||
|
|
||||||
|
return super().load_tests_for_label(label, discover_kwargs)
|
||||||
|
|
||||||
|
def build_suite(self, test_labels=None, extra_tests=None, **kwargs):
|
||||||
|
if test_labels:
|
||||||
|
return super().build_suite(
|
||||||
|
test_labels,
|
||||||
|
extra_tests=extra_tests,
|
||||||
|
**kwargs,
|
||||||
|
)
|
||||||
|
|
||||||
|
suite = self.test_suite()
|
||||||
|
repo_root = Path(__file__).resolve().parent.parent
|
||||||
|
|
||||||
|
for app_config in apps.get_app_configs():
|
||||||
|
test_dir = Path(app_config.path) / "tests"
|
||||||
|
if app_config.name.startswith("apps.") and test_dir.exists():
|
||||||
|
suite.addTests(
|
||||||
|
self.test_loader.discover(
|
||||||
|
start_dir=str(test_dir),
|
||||||
|
pattern=self.pattern,
|
||||||
|
top_level_dir=str(repo_root),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
if extra_tests:
|
||||||
|
suite.addTests(extra_tests)
|
||||||
|
return suite
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
[pytest]
|
|
||||||
DJANGO_SETTINGS_MODULE = config.settings.test
|
|
||||||
python_files = tests.py test_*.py *_tests.py
|
|
||||||
@@ -7,10 +7,9 @@ ipython>=8.25
|
|||||||
# Debug toolbar
|
# Debug toolbar
|
||||||
django-debug-toolbar>=4.4
|
django-debug-toolbar>=4.4
|
||||||
|
|
||||||
# Testing
|
# Testing
|
||||||
pytest>=8.2
|
coverage>=7.10
|
||||||
pytest-django>=4.8
|
factory-boy>=3.3
|
||||||
factory-boy>=3.3
|
|
||||||
|
|
||||||
# Linting & formatting
|
# Linting & formatting
|
||||||
black>=24.4
|
black>=24.4
|
||||||
@@ -22,4 +21,4 @@ django-stubs>=5.0
|
|||||||
|
|
||||||
# Pre-commit hooks
|
# Pre-commit hooks
|
||||||
pre-commit>=3.7
|
pre-commit>=3.7
|
||||||
commitizen>=4.13
|
commitizen>=4.13
|
||||||
|
|||||||
Reference in New Issue
Block a user