【发布时间】:2022-11-30 01:42:06
【问题描述】:
我想使用 pytest fixtures 来准备一个我想在一组测试中使用的对象。
我跟随 documentation 并在 something_fixture.py 中创建一个夹具,其范围设置为会议像这样:
import pytest
@pytest.fixture(scope="session")
def something():
return 'something'
然后在 test_something.py 中,我尝试像这样使用夹具:
def test_something(something):
assert something == 'something'
哪个不起作用,但是如果我像这样导入夹具:
from tests.something_fixture import something
def test_something(something):
assert something == 'something'
测试通过...
这个是进口的吗必要的?因为对我来说,根据文档,这还不清楚。
【问题讨论】: