我的系统python --version
上有Python 2.7.5
我有一个基本脚本,试图验证一些东西,断言是否错误。这是我创建的失败的简单测试。
注意早期的Asserts(2.7之前的版本)工作正常。
import unittest
class TestSuite (unittest.TestCase):
def test002_last_Chat(self):
logger.info("This will select the chat with the user who we cleared. .")
a.selectMenu('Start a Chat')
self.assertEqual("im", "im") #This assert works fine
self.assertIn ("a", "apple") #FAILS
self.assertIn ("a", "pple") #FAILS
logger.info ("test01")\
if __name__ == '__main__':
logger.info("Running test: "+scriptName)
a = IPHONE()
b = BROWSER()
c = SAWS()
myTest = TestSuiteRunner(TestSuite, scriptName, testDescription, device=device)
myTest.runtest()
运行时出现此错误
Test complete (ERROR): test002_last_Chat (__main__.TestSuite)
(<type 'exceptions.AttributeError'>, AttributeError("'TestSuite' object has no attribute 'assertIn'",), <traceback object at 0x3>)
Traceback (most recent call last):
File "/Users/drlazor/Documents/AIM/6-17/oscar/qa/clients/TRAVOLTA/scripts_iphone/iphoneAIM_close.sikuli/iphoneAIM_close.py", line 194, in test002_last_Chat
self.assertIn ("a", "apple")
AttributeError: 'TestSuite' object has no attribute 'assertIn'
我正在使用此文档http://docs.python.org/2/library/unittest.html#assert-methods作为指南。
答案 0 :(得分:2)
在某些版本的Python中似乎存在assertIn
的问题。这是一个应该有效的替代方案:
a = 'a'
apple = 'apple'
self.assertTrue(a in apple, '{} not in {}'.format(a, apple))