1 回答
TA贡献1820条经验 获得超2个赞
尝试向 @unittest.skip 装饰器添加一个字符串参数,如下所示:
import unittest
class TestThings(unittest.TestCase):
def test_1(self):
self.assertEqual(1,1)
@unittest.skip('skipping...')
def test_2(self):
self.assertEqual(2,4)
在 python 2.7 中不使用字符串参数运行会得到以下结果:
.E
======================================================================
ERROR: test_2 (test_test.TestThings)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/usr/lib64/python2.7/functools.py", line 33, in update_wrapper
setattr(wrapper, attr, getattr(wrapped, attr))
AttributeError: 'TestThings' object has no attribute '__name__'
----------------------------------------------------------------------
Ran 2 tests in 0.001s
而在 python 2.7 中使用文本运行给了我:
.s
----------------------------------------------------------------------
Ran 2 tests in 0.000s
OK (skipped=1)
添加回答
举报