pytest setup_class方法和数据库访问

时间:2019-02-16 02:37:29

标签: python-3.x pytest pytest-django

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)需要数据库访问权限

德米特里

0 个答案:

没有答案