首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >未找到fixture 'driver_init‘

未找到fixture 'driver_init‘
EN

Stack Overflow用户
提问于 2021-11-02 05:53:32
回答 1查看 70关注 0票数 0
代码语言:javascript
复制
import pytest

# Fixture for Firefox
from selenium import webdriver


@pytest.fixture(scope="class")
def driver_init(request):
    ff_driver = webdriver.Firefox()
    request.cls.driver = ff_driver
    yield
    ff_driver.close()


# Fixture for Chrome
@pytest.fixture(scope="class")
def chrome_driver_init(request):
    chrome_driver = webdriver.Chrome()
    request.cls.driver = chrome_driver
    yield
    chrome_driver.close()


@pytest.mark.usefixtures("driver_init")
class BaseTest:
    pass

它不工作,在我看来一切都是正确的,但仍然得到错误driver_init not found。我使用的是pythin版本3.9和mac os。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-11-02 12:46:58

我不确定,如果您忘记在最小示例中添加几行代码。在我看来,它没有像预期的那样工作,因为你有一个甚至没有构造函数或单元测试的BaseTest类,而另一个问题是pytest类应该以Test...开头才能被找到。

另请参阅pytest发现的约定:https://docs.pytest.org/en/latest/explanation/goodpractices.html#conventions-for-python-test-discovery

如果我使用您的代码并将BaseTest类更改为下面的代码,那么它对我来说工作得很好。

代码语言:javascript
复制
@pytest.mark.usefixtures("driver_init")
class TestBase:

    def test_test(self):
    """ This is a unit test """
       pass

现在,如果执行单元测试test_test,那么类TestBase将调用driver_init

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69805923

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档