This is in Python 2.7. I have a class called class A, and there are some attributes that I want to throw an exception when being set by the user:
myA = A()
myA.myattribute = 9 # this should throw an error
I want to write a unittest that ensures that this throws an error.
After creating a test class and inheriting unittest.TestCase, I tried to write a test like this:
myA = A()
self.assertRaises(AttributeError, eval('myA.myattribute = 9'))
But, this throws a syntax error. However, if I try eval('myA.myattribute = 9'), it throws the attribute error, as it should.
How do I write a unittest to test this correctly?
Thanks.
unittestsyntax.