use*_*719 83 django unit-testing skip django-unittest
如何在Django中强行跳过单元测试?
@skipif和@skipunless是我找到的全部内容,但我只想暂时跳过一个测试用于调试目的,同时我将一些事情弄清楚了.
Ray*_*oal 126
Python的unittest模块有一些装饰器:
有一点旧@skip:
from unittest import skip
@skip("Don't want to test")
def test_something():
...
Run Code Online (Sandbox Code Playgroud)
如果@skip由于某种原因无法使用,@skipIf应该工作.只是欺骗它总是跳过参数True:
@skipIf(True, "I don't want to run this test yet")
def test_something():
...
Run Code Online (Sandbox Code Playgroud)
如果您希望不运行某些测试文件,最好的方法可能是使用fab或使用其他工具并运行特定测试.
YPC*_*ble 55
Django 1.10 允许使用标签进行单元测试.然后,您可以使用该--exclude-tag=tag_name标记排除某些标记:
from django.test import tag
class SampleTestCase(TestCase):
@tag('fast')
def test_fast(self):
...
@tag('slow')
def test_slow(self):
...
@tag('slow', 'core')
def test_slow_but_core(self):
...
Run Code Online (Sandbox Code Playgroud)
在上面的示例中,要使用" slow"标记排除测试,您将运行:
$ ./manage.py test --exclude-tag=slow
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
26149 次 |
| 最近记录: |