from django.test import TestCase
from django.urls import reverse
class IndexViewTestCase(TestCase):
def test_view(self):
path = reverse('index')
response = self.client.get(path)
self.assertEqual(response.status_code, 200)
self.assertEqual(response.context_data['title'], 'Store')
self.assertTemplateUsed(response, 'products/index.html')
ошибка:
Launching pytest with arguments tests.py::IndexViewTestCase::test_view --no-header --no-summary -q in G:\Важное\Сохранения\Django-Projects\store\products
============================= test session starts =============================
collecting ...
tests.py:None (tests.py)
tests.py:6: in <module>
from products.models import Product, ProductCategory
models.py:3: in <module>
from users.models import User
..\users\models.py:3: in <module>
from django.contrib.auth.models import AbstractUser
C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\django\contrib\auth\models.py:3: in <module>
from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\django\contrib\auth\base_user.py:49: in <module>
class AbstractBaseUser(models.Model):
C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\django\db\models\base.py:127: in __new__
app_config = apps.get_containing_app_config(module)
C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\django\apps\registry.py:260: in get_containing_app_config
self.check_apps_ready()
C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\django\apps\registry.py:137: in check_apps_ready
settings.INSTALLED_APPS
C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\django\conf\__init__.py:92: in __getattr__
self._setup(name)
C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\django\conf\__init__.py:72: in _setup
raise ImproperlyConfigured(
E django.core.exceptions.ImproperlyConfigured: Requested setting INSTALLED_APPS, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
collected 0 items / 1 error
============================== 1 error in 0.63s ===============================
ERROR: not found: G:\Важное\Сохранения\Django-Projects\store\products\tests.py::IndexViewTestCase::test_view
(no name 'G:\\Важное\\Сохранения\\Django-Projects\\store\\products\\tests.py::IndexViewTestCase::test_view' in any of [<Module tests.py>])