【问题标题】:django testrunner not running my testsdjango testrunner 没有运行我的测试
【发布时间】:2024-01-14 09:34:01
【问题描述】:

我有以下 tests.py 文件:

from django.test import TestCase
from lxml import etree
import tempfile

import utils

class CreateSurveyFromCsvTextTests(TestCase):

    def parsesSurveyPassedInAsCsvAndReturnsXmlRepresentation(self):
        text = """"survey",,,,,
                ,"name","type","label","hint","required"
                ,"gps","geopoint","Record your current location",,"false"
                ,"start","start",,,
                ,"end","end",,,
                "settings",
                ,"form_title"
                ,"New survey" """

        xml = create_survey_from_csv_text(text)

        lxml.fromstring(xml)

当我使用python manage.py test 运行我的模块时,输出是

在 0.000 秒内运行 0 次测试

我知道跑步者正在获取文件,因为如果我进行了无效的导入,它会引发错误。

为什么没有调用测试?

【问题讨论】:

    标签: python django django-testing django-tests


    【解决方案1】:

    测试方法的名称需要以test_ 开头。这允许该类同时具有您可以编写的测试方法和帮助方法。

    因此,您应该将您的方法重命名为 test_parsesSurveyPassedInAsCsvAndReturnsXmlRepresentation(也可以缩短名称)。

    【讨论】:

    • 很好,工作。谢谢!我会尽快接受它;)
    最近更新 更多