我有一个常见的py.test fixture,我想在同一个模块中的不同测试文件中使用.在阅读py.test文档之后,建议将夹具添加到conftest.py文件中,该文件应该使夹具可用于模块中的所有文件.但由于某些原因,我似乎无法使用这个常用夹具来使用我的测试类.
#In conftest.py
import pytest
@pytest.fixture
def mock_data(scope="module"):
return ({'number_of_females_1': 14,
'number_of_females_2': 3,
'number_of_females_3': 19,
'number_of_males_1': 37)}
Run Code Online (Sandbox Code Playgroud)
然后在我的测试类文件中
Import pytest
from unittest import TestCase
@pytest.mark.usefixtures('mgmt_data')
class Test_param_sweeps(TestCase):
def test_Base_model(self, mgmt_data):
from pyugend.pyugend.Models import Base_model
t = Base_model(**mgmt_data)
assert isinstance(t, Base_model)
Run Code Online (Sandbox Code Playgroud)
文档说我没有必要导入mgmt_data夹具或任何东西.
运行此测试用例时出现的错误是:
self = <pyugend.tests.test_param_sweeps.Test_param_sweeps testMethod=test_Base_model>
result = <TestCaseFunction 'test_Base_model'>
def run(self, result=None):
orig_result = result
if result is None:
result = self.defaultTestResult()
startTestRun = getattr(result, 'startTestRun', None)
if startTestRun is not None:
startTestRun()
result.startTest(self) …Run Code Online (Sandbox Code Playgroud)