From 6692f1bf1943797a1136d9449d70abc4533109cf Mon Sep 17 00:00:00 2001 From: Andrey Smakotin Date: Tue, 6 Jan 2026 22:29:01 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9D=D0=B0=D1=81=D1=82=D1=80=D0=BE=D0=B9?= =?UTF-8?q?=D0=BA=D0=B0=20pytest=20=D0=B4=D0=BB=D1=8F=20=D0=BA=D0=BE=D1=80?= =?UTF-8?q?=D1=80=D0=B5=D0=BA=D1=82=D0=BD=D0=BE=D0=B9=20=D1=80=D0=B0=D0=B1?= =?UTF-8?q?=D0=BE=D1=82=D1=8B=20=D1=81=20django-tenants?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Добавлена конфигурация 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 тестов проекта. --- myproject/conftest.py | 16 ++++++++++++++++ myproject/orders/tests.py | 3 --- myproject/requirements.txt | 2 ++ pytest.ini | 11 +++++++++++ 4 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 myproject/conftest.py delete mode 100644 myproject/orders/tests.py create mode 100644 pytest.ini diff --git a/myproject/conftest.py b/myproject/conftest.py new file mode 100644 index 0000000..f8649b8 --- /dev/null +++ b/myproject/conftest.py @@ -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() diff --git a/myproject/orders/tests.py b/myproject/orders/tests.py deleted file mode 100644 index 7ce503c..0000000 --- a/myproject/orders/tests.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.test import TestCase - -# Create your tests here. diff --git a/myproject/requirements.txt b/myproject/requirements.txt index ebea27e..7ebcfd6 100644 --- a/myproject/requirements.txt +++ b/myproject/requirements.txt @@ -38,3 +38,5 @@ Unidecode==1.4.0 vine==5.1.0 wcwidth==0.2.14 whitenoise==6.6.0 +pytest==8.0.0 +pytest-django==4.7.0 diff --git a/pytest.ini b/pytest.ini new file mode 100644 index 0000000..151f5ee --- /dev/null +++ b/pytest.ini @@ -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