与另一个夹具一起使用时找不到 PyTest 夹具

PyTest fixture not found while using with another fixture

我是 python 的新手。我已经声明了一个固定装置 configure_loggers(),范围为 'session'。现在,我想在另一个夹具 setup_app() 之前使用这个夹具,它的作用域也为 'session'.

灯具 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 中导入解决了这个问题。

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