【问题标题】:Can not run tests in APITestCase无法在 APITestCase 中运行测试
【发布时间】:2020-01-21 20:01:36
【问题描述】:

项目结构

proj/
  apps/
    app1/
      ...
      tests.py
    ...
  proj/

tests.py

class UsersTestCase(APITestCase):
    def setUp(self):
        self.user = User.objects.get(id=3)
        self.client = APIClient()

    def test_users_list(self):
        ...

我运行 python manage.py test --settings=proj.settings.local 并看到 在 0.000 秒内运行 0 个测试

为什么?

【问题讨论】:

    标签: django django-rest-framework django-testing


    【解决方案1】:

    尝试将模块添加为测试参数

    python manage.py test --settings=proj.settings.local apps.app1
    

    如果仍然失败,请检查您的 INSTALLED_APPS 中是否有 'apps.app1'

    【讨论】:

    • AttributeError: module 'apps' has no attribute '__file__'
    • 你在apps文件夹中有__init__.py吗?
    猜你喜欢
    • 2022-11-12
    • 1970-01-01
    • 2019-12-19
    • 2010-09-30
    • 2015-09-26
    • 2014-10-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多