метод pytest setup_class и доступ к базе данных - PullRequest
0 голосов
/ 16 февраля 2019
import pytest
from . import utilization

pytestmark = pytest.mark.django_db
some_period = 'test' 

@pytest.mark.django_db
class TestUtilization(object):
    @classmethod
    def setup_class(self):
        self.period = some_period
        self.metric = utilization.Utilization(period=self.period)
        print('setup')

    def test_get_query_params(self, tprint):
        """Should return dict with start/end keys of datetime values"""
        # assert self.xxx == some_period
        tprint(self.period)
        tprint(self.metric)

    def test_call(self, tprint):
        """Test that we have desired fields and index of the metric"""
        pass

и я получаю это:

E       Failed: Database access not allowed, use the "django_db" 
mark, or the "db" or "transactional_db" fixtures to enable it.

Как мне это исправить?

В идеале мне нужен setup_class для работы только один раз, а для следующей строки self.metric = utilization.Utilization(period=self.period) требуется DBдоступ

Дмитрий

...