【问题标题】:Django unit test is not finding any testDjango单元测试没有找到任何测试
【发布时间】:2021-07-23 17:37:26
【问题描述】:

我想对test_models.py 进行单元测试,文件内容如下:

from django.test import TestCase
from django.contrib.auth import get_user_model


class ModelTest(TestCase):
    def test_create_user_with_email_successful(self):
        email = 'superuser@super.com'
        password = '9876543210'
        user = get_user_model().objects.create_user(
            email=email,
            password=password
        )

        self.assertEqual(user.email, email)
        self.assertTrue(user.check_password(password))

在我运行python manage.py test 之后,我得到了这个:

System check identified no issues (0 silenced).

----------------------------------------------------------------------
Ran 0 tests in 0.000s

OK

我的项目的文件结构如图

【问题讨论】:

    标签: django unit-testing django-tests django-3.2


    【解决方案1】:

    好的。我发现错误。文件夹 tests.py 不包含任何 __init__.py 文件。这就是 django 找不到测试文件的原因。所以它不会运行测试。

    最后在测试文件夹中添加__init__.py解决了问题

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-08-17
      • 1970-01-01
      • 1970-01-01
      • 2011-07-28
      • 1970-01-01
      • 1970-01-01
      • 2015-02-23
      相关资源
      最近更新 更多