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?
Make LiveServerTestCase not to call setUp() before each test
Asked Answered
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.
© 2022 - 2024 — McMap. All rights reserved.