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)
添加回答
舉報