AttributeError: TestSwitch instance has no attribute 'assertTrue'
AttributeError: TestSwitch instance has no attribute 'assertTrue'
我有以下 pyunit 测试用例代码,我在其中收集函数的结果(真或假)并使用它来驱动我的断言。但是,我收到 assertTrue 的 "no attribute" 错误。这里缺少什么?
我正在使用 python 2.7.8 和 PyUnit-1.4.1-py2.7 的 pyunit 版本。
当 运行 来自我的 Mac 的 Eclipse(pydev 插件)时,相同的代码工作正常。只有当我把它带到我的 Linux 框时,它才会抛出以下错误。所以对我来说,这看起来像是一些包不兼容的问题。
import json
import unittest
class TestSwitch(unittest.TestCase):
def testFunction(self):
self.assertTrue(True, "test case failed")
下面是测试套件 class。
import unittest
from mysample import TestSwitch
# Create an instance of each test case.
testCase = TestSwitch('testFunction')
# Add test cases to the test suite.
testSuite = unittest.TestSuite()
testSuite.addTest(testCase)
# Execute the test suite.
testRunner = unittest.TextTestRunner(verbosity=2)
testRunner.run(testSuite)
抛出以下错误。
bash-3.2$ python mysuite.py
testFunction (mysample.TestSwitch) ... ERROR
======================================================================
ERROR: testFunction (mysample.TestSwitch)
----------------------------------------------------------------------
Traceback (most recent call last):
File "workspace/pyunit/mysample.py", line 7, in testFunction
self.assertTrue(True, "test case failed")
AttributeError: TestSwitch instance has no attribute 'assertTrue'
----------------------------------------------------------------------
Ran 1 tests in 0.000s
FAILED (errors=1)
bash-3.2$
现在我已经找到了解决此问题的方法,方法是使用 'assertEqual' 与布尔值进行比较并且它有效。我不确定为什么 'assertTrue' 和 'assertFalse' 有问题。我没有更改任何包版本或任何东西。
变通代码如下。
17 def testFunction(self):
18 res = True
19 self.assertEqual(res, True, 'test case failed')
我有以下 pyunit 测试用例代码,我在其中收集函数的结果(真或假)并使用它来驱动我的断言。但是,我收到 assertTrue 的 "no attribute" 错误。这里缺少什么?
我正在使用 python 2.7.8 和 PyUnit-1.4.1-py2.7 的 pyunit 版本。
当 运行 来自我的 Mac 的 Eclipse(pydev 插件)时,相同的代码工作正常。只有当我把它带到我的 Linux 框时,它才会抛出以下错误。所以对我来说,这看起来像是一些包不兼容的问题。
import json
import unittest
class TestSwitch(unittest.TestCase):
def testFunction(self):
self.assertTrue(True, "test case failed")
下面是测试套件 class。
import unittest
from mysample import TestSwitch
# Create an instance of each test case.
testCase = TestSwitch('testFunction')
# Add test cases to the test suite.
testSuite = unittest.TestSuite()
testSuite.addTest(testCase)
# Execute the test suite.
testRunner = unittest.TextTestRunner(verbosity=2)
testRunner.run(testSuite)
抛出以下错误。
bash-3.2$ python mysuite.py
testFunction (mysample.TestSwitch) ... ERROR
======================================================================
ERROR: testFunction (mysample.TestSwitch)
----------------------------------------------------------------------
Traceback (most recent call last):
File "workspace/pyunit/mysample.py", line 7, in testFunction
self.assertTrue(True, "test case failed")
AttributeError: TestSwitch instance has no attribute 'assertTrue'
----------------------------------------------------------------------
Ran 1 tests in 0.000s
FAILED (errors=1)
bash-3.2$
现在我已经找到了解决此问题的方法,方法是使用 'assertEqual' 与布尔值进行比较并且它有效。我不确定为什么 'assertTrue' 和 'assertFalse' 有问题。我没有更改任何包版本或任何东西。
变通代码如下。
17 def testFunction(self):
18 res = True
19 self.assertEqual(res, True, 'test case failed')