feat(src/djinit/templates): scaffold pytest fixtures and configuration templates- New Features
- Added conftest.py template with Django test database, API client, and test user fixtures. - Added pytest.ini template configuring settings, test discovery, and custom markers. - Integrated pytest and coverage requirements into the project requirements template. - Enhancements - None - Bug Fixes - None
This commit is contained in:
3 files changed
+63
No files matched your search
@@ -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'
|
||||
)
|
||||
@@ -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
|
||||
@@ -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
|
||||
|
||||
Reference in new issue
Block a user