gpt4 book ai didi

python - Django 没有使用 manage.py 测试运行测试

转载 作者:行者123 更新时间:2023-11-28 22:47:28 25 4
gpt4 key购买 nike

我对 Django 的测试有疑问。我启动这个命令来运行测试:

$ python manage.py test gastrobook

gastrobook 是我的应用程序,tha comand 对于 Django 的文档来说很好,事实上它可以工作但不运行任何测试但是在 tests.py 中我已经写了一些测试!这是那个终端说:

$ python manage.py test gastrobook/
Creating test database for alias 'default'...

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

OK
Destroying test database for alias 'default'...

这是我的tests.py

from django.test import TestCase
from gastrobook.models import *
import datetime
from django.utils import timezone

# Create your tests here.
def create_recipe(title,desc,procedimento,pub_date,hard,time,person):
return Recipe.objects.create(title=title,desc=desc,procedimento=procedimento,pub_date=pub_date,hard=hard,time=time,person=person)

class RecipeTest(TestCase):
def setUp(self):
create_recipe("cui","dcnjenj","owcjc",timezone.now(),2,"5 ore",2)

def hard_no_more_than(self):
recipe = Recipe.objects.all()
for rec in recipe:
self.assertIn(rec.hard,range(1,10))

最佳答案

来自 unittest documentation

A testcase is created by subclassing unittest.TestCase. The three individual tests are defined with methods whose names start with the letters test. This naming convention informs the test runner about which methods represent tests.

将您的测试函数更改为 test_hard_no_more_than,然后测试运行器能够发现测试用例。

关于python - Django 没有使用 manage.py 测试运行测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26202189/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com