Python 2.7中的断言不适用于我的示例assertIn [英] Asserts in Python 2.7 not working for me example assertIn
问题描述
我在Mac上安装了python 2.7. (通过在终端中运行python -v进行验证) 当我尝试使用任何新的2.7断言方法时,都会收到AtributeError.我看过 http://docs.python.org/2/library/unittest.html 并且找不到任何东西. 2.6附带的Asserts都可以在EX Self.AssertEqual(x,x)中使用
I have python 2.7 installed on my Mac. (verified by running python -v in terminal) When I try to use any of the new 2.7 assert methods I get AtributeError. I have looked at http://docs.python.org/2/library/unittest.html and can't find anything. The Asserts that come with 2.6 all work Ex Self.AssertEqual (x,x)
下面是我的代码.当我调用assertIn时,我收到以下消息.
Below is my code. When I call the assertIn I get the below message.
* 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()
推荐答案
我怀疑您的代码未在您认为是的Python版本中运行.如果添加以下测试用例:
I suspect that your code is not running in the version of Python that you think it is. If you add the following test case:
def test_python_version(self):
import sys
assert sys.version_info[0:3] >= (2,7,0)
如果该测试用例失败,则说明您所使用的Python版本不足以包含self.assertIn()
.
If that test case fails, then you're not running on a version of Python new enough to contain self.assertIn()
.
这篇关于Python 2.7中的断言不适用于我的示例assertIn的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!