Я пытаюсь использовать боковую панель тестирования VSCode с моим проектом Django, но не удается найти pytest.
Вот команды, которые я выполнил для создания этого примера проекта:
Код: Выделить всё
django-admin startproject LearningPytestКод: Выделить всё
pip install django-pytestКод: Выделить всё
DjangoPyTesting/
└───LearningPytest/
├───LearningPytest/
│ ├───__init__.py
│ ├───asgi.py
│ ├───basic_tests.py
│ ├───settings.py
│ ├───urls.py
│ ├───wsgi.py
├───manage.py
└───pytest.ini
Код: Выделить всё
[pytest]
DJANGO_SETTINGS_MODULE = LearningPytest.settings
python_files = tests.py test_*.py *_tests.py
python_classes = Test*
python_functions = test_*
Код: Выделить всё
class TestBasicMath:
def setup_method(self, method):
self.x = 2
self.y = 3
def test_addition(self):
assert self.x + self.y == 5
def test_subtraction(self):
assert self.y - self.x == 1
def test_multiplication(self):
assert self.x * self.y == 6
Это меня смущает, потому что в моем проекте я запускаю следующую команду:
Код: Выделить всё
DjangoPytesting\LearningPytest>pytestКод: Выделить всё
platform win32 -- Python 3.11.5, pytest-7.4.4, pluggy-1.3.0
rootdir: C:\Users\{me}\Desktop\DjangoPytesting\LearningPytest
configfile: pytest.ini
plugins: anyio-4.3.0, django-4.9.0
collected 3 items
LearningPytest\basic_tests.py ...platform win32 -- Python 3.11.5, pytest-7.4.4, pluggy-1.3.0
rootdir: C:\Users\{me}\Desktop\DjangoPytesting\LearningPytest
configfile: pytest.ini
plugins: anyio-4.3.0, django-4.9.0
collected 3 items
LearningPytest\basic_tests.py ... 3 passed in 0.02s
Код: Выделить всё
DjangoPytesting>pytestКод: Выделить всё
platform win32 -- Python 3.11.5, pytest-7.4.4, pluggy-1.3.0
rootdir: C:\Users\{me}\Desktop\DjangoPytesting
plugins: anyio-4.3.0, django-4.9.0
collected 0 items
no tests ran in 0.01s
Неудачные попытки решения:
- с использованием «> Разработчик: перезагрузить окно»
- https://pytest-django.readthedocs.io/en/latest/tutorial. html
- переименование файла ('test.py', 'tests.py', 'LearningPytest_tests.py')
Подробнее здесь: https://stackoverflow.com/questions/790 ... go-project