Reputation: 6657
I have one problem with testing django app by using LiveServerTestCase. LiveServerTestCase execute setUp() function before executing each test. But I'm using factory-boy's factories to create objects for testing (users, items, etc...). And the same objects are created before executing each test. How can I create this objects one time and make all tests to see this objects in database?
Upvotes: 1
Views: 947
Reputation: 15154
setUp()
gets called before every test.
If you want to create the objects once for the entrire test case, you can use setUpClass()
instead.
E.g.
class SomeTest(LiveServerTestCase):
@classmethod
def setUpClass(cls):
# create objects here
LiveServerTestCase.setUpClass()
Don't forget to call LiveServerTestCase.setUpClass()
or the live server won't function properly.
Upvotes: 1