I am writing some unit tests which I have simplified to the following:
class BuyTicket(TestCase):
ipn = {
"payer_email": "bishan_1233269544_per@gmail.com",
"quantity": "1",
}
def setUp(self):
self.attendee = create_user(username='attendee', \
email='attendee@foobar.com')
self.client = Client()
def test_1(self):
self.quantity = 100
self.ipn['quantity'] = self.quantity
def test_2(self):
# I would like to use the updated values of ipn['quantity']
# in this method
I know I could do this using global but it’s generally regarded to be bad form. Am I missing something obvious?
I don’t think you want to do that:
I think Unittest creates a new instance of BuyTicket for each test function, and calls setUp before each test.
If one test depends on another like you describe, you should factor out the dependency into separate code or call from the setup() function. If you really need to do what you say, then declare ipn at the module level.