首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >pytest-selenium已安装,但不能作为pytest的插件使用。我做错了什么?

pytest-selenium已安装,但不能作为pytest的插件使用。我做错了什么?
EN

Stack Overflow用户
提问于 2021-06-17 00:35:01
回答 1查看 16关注 0票数 0

我已经安装了pytest-selenium,但我不能将其与pytest一起使用。

代码语言:javascript
复制
  def test_sanity(selenium):
E       fixture 'selenium' not found
>       available fixtures: cache, capfd, capfdbinary, caplog, capsys, capsysbinary, check, cov, dash_br, dash_duo, dash_process_server, dash_thread_server, dashr, dashr_server, doctest_namespace, install_cbm_dash, install_dir, metadata, mock, mocker, monkeypatch, most_recent_installer_exe, no_cover, pytestconfig, record_property, record_testsuite_property, record_xml_attribute, recwarn, run_installer, tmp_path, tmp_path_factory, tmpdir, tmpdir_factory, uninstall_after_run
>       use 'pytest --fixtures [testpath]' for help on them.

λ pytest --fixtures
======================================================= test session starts ======================================================= platform win32 -- Python 3.6.8, pytest-4.6.3, py-1.8.0, pluggy-0.12.0
rootdir: C:\Users\dbak\Downloads\cmder
plugins: allure-pytest-2.7.0, dash-1.7.0, flaky-3.6.0, check-0.3.5, cov-2.10.0, html-1.21.1, metadata-1.8.0, mock-1.10.4, profiling-1.7.0

导致这种情况的根本原因可能是什么?我怎么才能修复它?

EN

回答 1

Stack Overflow用户

发布于 2021-07-26 21:52:50

这意味着没有名为selenium的fixture。

您可能需要初始化selenium。你可以在你想要使用的每个函数中这样做,但这是相当烦人的。因此,更好的替代方法是在conftest.py中添加一个函数。这样,您就可以继续使用selenium作为测试函数的参数。

代码语言:javascript
复制
import pytest

@pytest.fixture()
def selenium():
    #do some initialisation for selenium here.
    return your_selenium_instance
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68006779

复制
相关文章

相似问题

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