pytest-selenium установлен, но недоступен как плагин для pytest. Что я сделал не так?
Я установил 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
Что может быть основной причиной этого? Как я могу это исправить?
1 ответ
Это означает, что не вызывается прибор.
Вероятно, вам нужно инициализировать селен. Вы можете сделать это внутри каждой функции, которую хотите использовать, но это довольно раздражает. Поэтому лучшей альтернативой является добавление функции в
conftest.py
. Таким образом, вы можете продолжать использовать
selenium
в качестве аргумента для ваших тестовых функций.
import pytest
@pytest.fixture()
def selenium():
#do some initialisation for selenium here.
return your_selenium_instance