Django运行特定测试

时间:2019-06-14 07:12:27

标签: django django-testing django-tests

在“我的项目”中有多个测试文件,并且如果我运行

python manage.py tests

完成测试需要大量时间,我不希望这样。

我只想像运行测试一样运行特定的测试文件

project/todo/tests/test_todo.py
project/accounts/tests/test_signup.py
project/todo/tests/test_archive.py

还有更多类似这些内容:

现在我只想运行project/todo/tests/test_todo.py,我该怎么办?

2 个答案:

答案 0 :(得分:2)

您只需执行python manage.py test project.todo.tests.test_todo。注意这里的区别,而不是将其作为文件提供,可以将其作为软件包提供。如果要在测试套件中运行特定的测试用例,则可以以相同的方式进行。 python manage.py test project.todo.tests.test_todo.TestSuiteClass.TestCase

答案 1 :(得分:0)

您可以使用以下命令运行特定的测试。

python manage.py test -nk appname.test_folder.test_file

-n, --nomigrations    Tells Django to NOT use migrations and create all
                        tables directly.
-k, --keepdb          Preserves the test DB between runs.
相关问题