【发布时间】:2019-07-17 16:14:13
【问题描述】:
我是 python 新手。我已经声明了一个夹具configure_loggers(),范围为“会话”。现在,我想在另一个夹具 setup_app() 之前使用这个夹具,它也被定义为“会话”。
夹具 1:
@pytest.fixture(scope='session')
def configure_loggers(request):
LOGGER.setLevel(logging.WARNING)
logging.getLogger("requests").setLevel(logging.WARNING)
logging.getLogger("urllib3").setLevel(logging.WARNING)
logging.getLogger().setLevel(logging.INFO)
夹具 2:
from fixtures.logger_config import configure_loggers
@pytest.fixture(scope='session')
def frapp(configure_loggers, request, context):
start_appium()
# do some other stuff
我尝试将日志记录装置添加到参数以及@pytest.mark.usefixtures('configure_loggers')。但是我收到以下错误:
fixture 'configure_loggers' not found
> available fixtures: cache, capfd, caplog, capsys, capturelog, context, doctest_namespace, enable_voice, frapp, launch_app, login, metadata, monkeypatch, pytestconfig, record_xml_property, recwarn, skip_tests_for_ios, tmpdir, tmpdir_factory
> use 'pytest --fixtures [testpath]' for help on them.
我也尝试将灯具放在同一个文件中。但是,仍然出现同样的错误。
如何调试这个问题?
【问题讨论】:
-
移除夹具导入,将夹具代码移至测试模块或
conftest.py。 -
@hoefling - 您的解决方案对我有用。我稍微调整了一下。在下面添加了答案。
标签: python-2.7 pytest fixtures