0

我已经安装了 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

这可能是什么根本原因?我该如何解决?

4

1 回答 1

0

这意味着没有名为selenium.

您可能需要初始化硒。您可以在要使用的每个函数中执行此操作,但这很烦人。因此,更好的选择是在conftest.py. 这样您就可以继续将selenium其用作测试函数的 arg。

import pytest

@pytest.fixture()
def selenium():
    #do some initialisation for selenium here.
    return your_selenium_instance
于 2021-07-26T13:52:50.120 回答