我试图解决一个问题,那就是:-
unittest.TestCase
类派生的类TestIsEvenMethod
。
unittest
模块并使用它的TestCase
实用程序李>TestIsEvenMethod
内定义一个测试test_isEven1
,检查isEven(5)
是否返回False
。
assertEqual
方法验证函数输出是否具有预期的输出李>unittest.main()
李>我的代码用于解决上述问题
def isEven(num):
return num%2==0
import unittest
class TestIsEvenMethod(unittest.TestCase):
def test_isEven1(self):
self.assertEqual(isEven(5), False)
if __name__ == '__main__':
unittest.main()
但是,我得到以下错误:
E
======================================================================
ERROR: /root/ (unittest.loader._FailedTest)
----------------------------------------------------------------------
AttributeError: module '__main__' has no attribute '/root/'
----------------------------------------------------------------------
Ran 1 test in 0.001s
FAILED (errors=1)
An exception has occurred, use %tb to see the full traceback.
SystemExit: True
您应该在main函数中编写以下代码:
相关问题 更多 >
编程相关推荐