【问题标题】:Django Running Particular TestDjango 运行特定测试
【发布时间】:2019-06-14 07:12:27
【问题描述】:

在我的项目中不止一个测试文件,如果我运行

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 我该怎么做?

【问题讨论】:

    标签: django django-testing django-tests


    【解决方案1】:

    你可以简单地做python manage.py test project.todo.tests.test_todo。观察这里的区别而不是把它作为一个文件,你可以把它作为一个包。如果你想在测试套件中运行一个特定的测试用例,你可以以同样的方式继续。 python manage.py test project.todo.tests.test_todo.TestSuiteClass.TestCase.

    【讨论】:

    • @mamuncode 如果这解决了问题,请考虑投票并接受答案。
    【解决方案2】:

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

    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.
    

    【讨论】:

      猜你喜欢
      • 2015-06-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多