【问题标题】:PyTest fixture not found while using with another fixture与另一个夹具一起使用时找不到 PyTest 夹具
【发布时间】: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


【解决方案1】:

我通过在conftest.py 中执行此导入解决了这个问题。

from fixtures.logger_config import configure_loggers
  • 注意:夹具仍在单独的文件中。

【讨论】:

  • 我猜你的意思是conftest.py
猜你喜欢
  • 1970-01-01
  • 2016-07-27
  • 1970-01-01
  • 2020-06-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-12-17
  • 1970-01-01
相关资源
最近更新 更多