Python - test a property throws exception
问题 Given: def test_to_check_exception_is_thrown(self): # Arrange c = Class() # Act and Assert self.assertRaises(NameError, c.do_something) If do_something throws an exception the test passes. But I have a property, and when I replace c.do_something with c.name = "Name" I get an error about my Test Module not being imported and Eclipse highlights the equals symbol. How do I test a property throws an exception? Edit: setattr and getattr are new to me. They've certainly helped in this case, thanks.