diff --git a/src/djinit/templates/project/conftest.py-tpl b/src/djinit/templates/project/conftest.py-tpl new file mode 100644 index 0000000..a07c40f --- /dev/null +++ b/src/djinit/templates/project/conftest.py-tpl @@ -0,0 +1,46 @@ +#--------------------------------------------------# +# The following was generated by djinit: # +#--------------------------------------------------# + +import os +import sys +import django +from pathlib import Path + +# Add project to path +sys.path.insert(0, str(Path(__file__).parent.parent)) + +# Configure Django settings +os.environ.setdefault('DJANGO_SETTINGS_MODULE', '[[ module_name ]].settings.development') +django.setup() + +import pytest + + +@pytest.fixture(scope="session") +def django_db_setup(): + """Setup test database.""" + from django.conf import settings + settings.DATABASES['default'] = { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': ':memory:', + } + + +@pytest.fixture +def api_client(): + """Return a test client.""" + from rest_framework.test import APIClient + return APIClient() + + +@pytest.fixture +def user(db): + """Create a test user.""" + from django.contrib.auth import get_user_model + User = get_user_model() + return User.objects.create_user( + username='testuser', + email='test@example.com', + password='testpass123' + ) \ No newline at end of file diff --git a/src/djinit/templates/project/pytest.ini-tpl b/src/djinit/templates/project/pytest.ini-tpl new file mode 100644 index 0000000..55ce09d --- /dev/null +++ b/src/djinit/templates/project/pytest.ini-tpl @@ -0,0 +1,14 @@ +#--------------------------------------------------# +# The following was generated by djinit: # +#--------------------------------------------------# + +[pytest] +DJANGO_SETTINGS_MODULE = [[ module_name ]].settings.development +python_files = tests.py test_*.py *_tests.py +python_classes = Test* *Tests *Test +python_functions = test_* +addopts = --strict-markers --tb=short +testpaths = [[ app_names ]] +markers = + slow: marks tests as slow (deselect with '-m "not slow"') + integration: marks tests as integration tests \ No newline at end of file diff --git a/src/djinit/templates/project/requirements-tpl b/src/djinit/templates/project/requirements-tpl index 9dbb655..bad8209 100644 --- a/src/djinit/templates/project/requirements-tpl +++ b/src/djinit/templates/project/requirements-tpl @@ -13,6 +13,9 @@ whitenoise django-tailwind-cli # @IF use_tailwind django-htmx # @IF use_htmx django-vite # @IF use_vite +pytest # @IF use_pytest +pytest-django # @IF use_pytest +pytest-cov # @IF use_pytest # @IF database_type == 'mysql' mysqlclient # @ELSE