我的Mac上安装了python 2.7。 (通过在终端中运行python -v验证) 当我尝试使用任何新的2.7断言方法时,我得到AtributeError。我看过http://docs.python.org/2/library/unittest.html但找不到任何东西。与2.6一起出现的断言所有工作Ex Self.AssertEqual(x,x)
以下是我的代码。当我调用assertIn时,我收到以下消息。
* Test complete (ERROR): test012_Add_user2 (__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/7-16/oscar/qa/clients/TRAVOLTA/scripts_iphone/Add_Favorites.sikuli/Add_Favorites.py", line 112, in test012_Add_user2
self.assertIn (foo, foo2)
AttributeError: 'TestSuite' object has no attribute 'assertIn'
下面是我的代码
import unittest
import datetime
from sikuli import *
scriptName = os.path.basename(sys.argv[0])
addImagePath( os.path.join("scripts", scriptName) )
class TestSuite (unittest.TestCase):
#Need to add some Iphone clearing of favorites
def test001_start_IPhone(self):
logger.info (" Start aim iphone application")
showEnvironmentSettings()
a.startApp()
version = a.login(username1, password)
myTest.results['deviceVersion'] = version
wait(2)
def test012_Add_user2(self):
logger.info ("Add User 2 to the Favorites")
a.mFriends_Favorites_addNewFavs((username3[-3:]))
Fav=a.mFriends_Favorites_getAllFavs()
logger.info("assertin is tried.... will see")
#assertIn(Fav, Fav2)
self.assertIn ("foo", "foo2") #foo
for item in Fav:
logger.info (item)
logger.info ("HSJDKSKJDHSAKJDHSAKJDHSA LOOOP 2")
if (username3[-3:])not in item:
logger.info(item)
logger.info(username3[-3:])
logger.info ("dkfjlfjskl FOUND 062")
self.assert ("The screenName %s was not added to the list" %username3)
def test016_Ck_Favorite_presence(self):
pres=a.mFriends_Favorites_checkUserPresence(username3[-3:])
self.assertEqual( pres, 'Offline' )
logger.info("Presence state is '%s'" %pres)
if __name__ == '__main__':
logger.info("Running test: "+scriptName)
a = IPHONE()
b = BROWSER()
c = SAWS()
myTest = TestSuiteRunner(TestSuite, scriptName, testDescription, device=device)
myTest.runtest()
答案 0 :(得分:1)
我怀疑你的代码没有在你认为的Python版本中运行。如果添加以下测试用例:
def test_python_version(self):
import sys
assert sys.version_info[0:3] >= (2,7,0)
如果该测试用例失败,那么您没有运行足以包含self.assertIn()
的Python版本。