2

I have Python 2.7.5 on my system python --version I have a basic script that tries to verify something and assert if false. Here is the simple test I created that is failing. Note Early on Asserts (pre 2.7) works fine.

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()

I get this error when I run it

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'

I am using this documentation http://docs.python.org/2/library/unittest.html#assert-methods as a guide.

4

1 回答 1

3

assertIn在某些版本的 Python 中似乎存在问题。这是一个应该有效的替代方案:

a = 'a'
apple = 'apple'
self.assertTrue(a in apple, '{} not in {}'.format(a, apple))
于 2013-07-17T18:02:29.670 回答