运行所有测试后django 1.6 [英] running all tests post django 1.6

查看:122
本文介绍了运行所有测试后django 1.6的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在django 1.5及更早版本中,运行 python manage.py test 将默认运行项目中的所有测试(包括django.contrib中的所有测试)。在版本1.6之后,默认行为是运行当前目录中的所有测试。

In django 1.5 and earlier, running python manage.py test would, by default, run all tests in a project (including all those in django.contrib). Subsequent to version 1.6, the default behaviour is to run all the tests in the current directory.

运行所有测试的最佳方法(v 1.6)或者没有django.contrib测试?

What is the best way (v 1.6) to run all tests, either with or without the django.contrib tests?

推荐答案

Django 1.6 将默认测试运行器更改为:

Django 1.6 changed the default test runner to:

TEST_RUNNER = 'django.test.runner.DiscoverRunner'

您可以通过添加到 settings.py 来获取旧的行为:

You can get the old behaviour back by adding to your settings.py:

TEST_RUNNER = 'django.test.simple.DjangoTestSuiteRunner'

如发行说明中所述:


上一个运行程序(django.test.simple.DjangoTestSuiteRunner)只能在INSTALLED_APPS中的Python包的models.py和tests.py模块中找到测试。

The previous runner (django.test.simple.DjangoTestSuiteRunner) found tests only in the models.py and tests.py modules of a Python package in INSTALLED_APPS.

新的运行程序(django.test.runner.DiscoverRunner)使用unittest2内置的测试发现功能(Python 2.7+标准库中的unittest版本,并与Django绑定)。通过测试发现,测试可以位于与模式测试* .py相匹配的任何模块中。

The new runner (django.test.runner.DiscoverRunner) uses the test discovery features built into unittest2 (the version of unittest in the Python 2.7+ standard library, and bundled with Django). With test discovery, tests can be located in any module whose name matches the pattern test*.py.

新的流程需要一个列表要发现测试的模块的虚线路径,所以您也可以通过以下方式从 django contrib 运行测试:

The new runner expects a list of dotted path of modules where tests shall be discovered, so you can also run the tests from django contrib this way:

python manage.py test myproject django.contrib path.to.someotherapp

这将使自动运行 INSTALLED_APPS 中的应用程序的所有测试。对于一个更复杂的解决方案,您可以编写自己的运行程序,从旧的和新的运行程序。

This will not run all tests from apps in INSTALLED_APPS automatically though. For a more complex solution, you could write your own runner, taking from both the old and new runner.

还要注意,通常不需要运行测试来自 django.contrib ,因为这些不会测试您的应用程序,而是Django发行版。 Django拥有更多的测试,不能由任何一个运行者运行。

Also note that it usually shouldn't be necessary to run tests from django.contrib, as these are not testing your application, but rather the Django distribution. Django ships with even more tests, which are not run by either runner.

这篇关于运行所有测试后django 1.6的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆