簡體   English   中英

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都可以自動執行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()

我懷疑您的代碼未在您認為的Python版本中運行。 如果添加以下測試用例:

def test_python_version(self):
    import sys
    assert sys.version_info[0:3] >= (2,7,0)

如果該測試用例失敗,則說明您沒有在足夠新的Python版本上運行以包含self.assertIn()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM