Настройка pytest для корректной работы с django-tenants

Добавлена конфигурация pytest.ini с правильным pythonpath для поддержки Django проекта в подкаталоге myproject. Создан conftest.py для инициализации Django при запуске тестов.

Изменения:
- Добавлен pytest.ini с настройками DJANGO_SETTINGS_MODULE и pythonpath
- Создан myproject/conftest.py для автоматической настройки Django
- Удален устаревший orders/tests.py
- Обновлен requirements.txt

Теперь VS Code корректно обнаруживает все 119 тестов проекта.
This commit is contained in:
2026-01-06 22:29:01 +03:00
parent 52d5f6fd9f
commit 6692f1bf19
4 changed files with 29 additions and 3 deletions

16
myproject/conftest.py Normal file
View File

@@ -0,0 +1,16 @@
# -*- coding: utf-8 -*-
"""
Конфигурация pytest для Django проекта с django-tenants
"""
import os
import django
from django.conf import settings
# Устанавливаем переменную окружения для settings
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'myproject.settings')
# Инициализируем Django
def pytest_configure(config):
"""Настройка Django перед запуском тестов"""
if not settings.configured:
django.setup()

View File

@@ -1,3 +0,0 @@
from django.test import TestCase
# Create your tests here.

View File

@@ -38,3 +38,5 @@ Unidecode==1.4.0
vine==5.1.0 vine==5.1.0
wcwidth==0.2.14 wcwidth==0.2.14
whitenoise==6.6.0 whitenoise==6.6.0
pytest==8.0.0
pytest-django==4.7.0

11
pytest.ini Normal file
View File

@@ -0,0 +1,11 @@
[pytest]
DJANGO_SETTINGS_MODULE = myproject.settings
python_files = tests.py test_*.py *_tests.py
python_classes = Test* *Tests
python_functions = test_*
testpaths = myproject
pythonpath = myproject
addopts = --tb=short --strict-markers --reuse-db
# Django database setup
django_find_project = true