Make LiveServerTestCase not to call setUp() before each test
Asked Answered
Q

1

1

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?

Quasimodo answered 21/10, 2012 at 11:31 Comment(0)
E
1

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.

Exclosure answered 26/12, 2012 at 9:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.