Django找不到嵌套测试

问题描述 投票:0回答:1

我具有以下文件结构:

project -
   - resources
       -__init__.py
       - core
          __init__.py
          test.py

我的测试代码如下:

class TestEmailHelper(TestCase):

def test_send_mail(self):
    EmailHelper.send_email(EmailHelper.SLUGS.ORDER_COMPLETED, '[email protected]', {})
    assert len(mail.outbox) == 1, "Inbox is not empty"

这是应用程序apps.py文件中的配置:

class CoreConfig(AppConfig):
name = 'resources.core'

而且,当然,这是在我的INSTALLED_APPS中,除了查找测试之外,它的工作状况非常好。

[如果我尝试运行所有测试,则会收到响应'没有运行测试,请检查测试的配置设置。

如果使用此命令,它将起作用:

python3 manage.py test resources/core

如果使用此命令,则在寻找'core'时出现找不到模块的错误:

python3 manage.py test core

在我看来,这可能与我的应用程序嵌套有关,因为当我不向拍子添加'resources'时会导致错误。但我不确定该如何解决。

django django-testing
1个回答
0
投票

Django的默认行为是使用名为tests而不是test的模块。因此,请尝试将模块名称更改为tests或配置您自己的测试运行程序以查找名为test的模块。

© www.soinside.com 2019 - 2024. All rights reserved.