我已经安装了pytest-selenium,但我不能将其与pytest一起使用。
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导致这种情况的根本原因可能是什么?我怎么才能修复它?
发布于 2021-07-26 21:52:50
这意味着没有名为selenium的fixture。
您可能需要初始化selenium。你可以在你想要使用的每个函数中这样做,但这是相当烦人的。因此,更好的替代方法是在conftest.py中添加一个函数。这样,您就可以继续使用selenium作为测试函数的参数。
import pytest
@pytest.fixture()
def selenium():
#do some initialisation for selenium here.
return your_selenium_instancehttps://stackoverflow.com/questions/68006779
复制相似问题