user2502671
user2502671

Reputation: 41

Python 2.7 assertin gets error object has no attribute

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.

Upvotes: 2

Views: 1394

Answers (1)

Nate
Nate

Reputation: 925

There seems to be an issue with assertIn in some versions of Python. Here's an alternative that should work:

a = 'a'
apple = 'apple'
self.assertTrue(a in apple, '{} not in {}'.format(a, apple))

Upvotes: 3

Related Questions