【发布时间】:2019-02-25 14:15:01
【问题描述】:
我正在使用 pytest 并尝试创建应该在我的项目的许多类中使用的对象。 我正在尝试将对象传递给其中一个类,但 pycharm 显示“未解析的引用 'custom_inst'。
这是我的代码:
conftest.py:
@pytest.fixture(scope="function", autouse=True)
def fixture_example(request):
custom_inst = FixtureClass()
yield custom_inst
custom_inst.do_something()
某类:
@pytest.mark.usefixtures('fixture_example')
class DummyClass(object):
def __init__(self, arg1=None, arg2=None):
self.arg1 = arg1
self.arg2 = arg2
self.custom_inst = fixture_example
如何将实例“custom_inst”作为类成员传递给我的 DummyClass?
谢谢。
【问题讨论】:
-
明白,谢谢