我在pycharm中運行unittests時遇到問題。第一類'KnownValues'運行,但其他類不會被檢查。PyCharm似乎並未運行所有單元測試
import roman
import unittest
class KnownValues(unittest.TestCase):
def test_too_large(self):
'''to_roman should fail with large input'''
self.assertRaises(roman.OutOfRangeError, roman.to_roman, 4000)
def test_too_small(self):
ls = [0,-1,-25,-60]
for x in ls:
self.assertRaises(roman.OutOfRangeError, roman.to_roman, x)
def test_non_int(self):
ls = [1.5, -6.5, 6.8,12.9, "hello wold", "nigga123"]
for x in ls:
self.assertRaises(roman.TypeError, roman.to_roman, x)
class Test2(unittest.TestCase):
def test1(self):
assert 1 == 1
if __name__ == '__main__':
unittest.main()
您是否驗證過,這與您在PyCharm外部運行程序時的行爲不同? – holdenweb
如果將測試方法的名稱從test1更改爲test_1會怎樣? – Charlie
@Charlie no pycharm即使我將其更改爲test_1,它也不運行1 – Bl4ckC4t