pytest:将测试分组到类中并使用测试装置

时间:2019-02-28 13:49:09

标签: python unit-testing pytest

我试图使用类对单元测试进行分组,并重用某些设置代码-在这里使用pytest测试装置。我试图复制this example

import pytest
from dataliner import core


@pytest.fixture(scope="class")
def dl_core():
    dl_core = core.DataLinerCore()
    dl_core.boot()
    yield dl_core

@pytest.mark.usefixtures("dl_core")
class TestTrend:

    def test_with_codes(self):
        trend = self.dl_core.get_combination_trend(
            included_codes=["I130016", "I130017"],
            interval="w",
        )

我没有看到与示例的区别,但是我的代码因以下原因而失败:

================================================================================ FAILURES ================================================================================
_______________________________________________________________________ TestTrend.test_with_codes ________________________________________________________________________

self = <test_core.TestTrend object at 0x1a1e1cfc18>

    @pytest.mark.smoke
    def test_with_codes(self):
>       trend = self.dl_core.get_combination_trend(
            included_codes=["I130016", "I130017"],
            interval="w",
        )
E       AttributeError: 'TestTrend' object has no attribute 'dl_core'

tests/test_core.py:16: AttributeError

0 个答案:

没有答案