M
M
maxclax2015-04-24 21:06:40
Django
maxclax, 2015-04-24 21:06:40

Why doesn't setup_class work in pytest?

Started learning pytest-django and ran into the following problem. I have class:

@pytest.mark.django_db
class TestNews:
    ###############
    #### Setup ####
    ###############

    def setup_class(cls):
        print("!!! In setup class !!!")
        cls.COUNT = 50
        NewsFactory.create_batch(is_allowed=True, size=cls.COUNT)

when debugging, it is clear that setup_class calls at the beginning of all tests, but I get the following error - there is no such table news_news. That is, when you run the tests, the database is not created at all.
If I use setup instead of setup_class, I see that the method call before each test and the database creates successfully and all tests pass. Why is that? What did I not specify? I need to call setup_class only once at the beginning of all tests from this class.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander, 2015-04-24
@ROR191505

Most likely, the methods that need to be overridden are named like this:
setUpClass
tearDownClass

M
marazmiki, 2015-04-25
@marazmiki

There is a suspicion that setup_class differs from setup in much the same way that __new__ differs from __init__. And there is no less serious suspicion that you want the unnatural.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question