【问题标题】:pytest says fixture not found while i call thispytest 说我打电话时找不到夹具
【发布时间】:2021-03-13 14:33:11
【问题描述】:

我正在使用 pytest 调用以下代码。

@pytest.fixture(scope='class')
    def driver_init(request):
        ch_driver = webdriver.Chrome(executable_path=Data.Ch_exe_path)
        request.cls.driver = ch_driver
        yield
        ch_driver.close()
    
    
    @pytest.mark.usefixtures("driver_init")

我收到一条错误消息

未找到夹具“driver_init”。可用的固定装置:缓存、capfd、capfdbinary、caplog、capsys、capsysbinary、doctest_namespace、extra、metadata、monkeypatch、pytestcon 图,record_property,record_testsuite_property,record_xml_attribute,recwarn,testrun_uid,tmp_path,tmp_path_factory,tmpdir,tmpdir_factory , worker_id。

【问题讨论】:

  • 我觉得没问题 - 你能在装饰器之后显示测试类吗?是否有更多代码使用该夹具?

标签: python python-3.x pytest


【解决方案1】:

当我将函数名称更改为“setup”而不是“driver_init”时,它正在工作。

【讨论】:

    猜你喜欢
    • 2016-07-27
    • 1970-01-01
    • 2020-12-17
    • 1970-01-01
    • 2021-08-30
    • 2022-01-21
    • 1970-01-01
    • 2019-07-17
    • 2021-09-03
    相关资源
    最近更新 更多