У меня есть файл контеста
импорт Pytest
из селена импорт вебдрайвер
@pytest.yield_fixture()
def setUp():
print("Running method level setUp")
yield
print("Running method level tearDown")
@pytest.yield_fixture(scope="class")
def oneTimeSetUp(request, browser):
print("Running one time setUp")
if browser == 'firefox':
baseURL = "https://f"
driver = webdriver.Firefox()
driver.maximize_window()
driver.implicitly_wait(3)
driver.get(baseURL)
print("Running tests on FF")
else:
baseURL = "https://f"
driver = webdriver.Chrome()
driver.get(baseURL)
print("Running tests on chrome")
if request.cls is not None:
request.cls.driver = driver
yield driver
driver.quit()
print("Running one time tearDown")
def pytest_addoption(parser):
parser.addoption("--browser")
parser.addoption("--osType", help="Type of operating system")
@pytest.fixture(scope="session")
def browser(request):
return request.config.getoption("--browser")
@pytest.fixture(scope="session")
def osType(request):
return request.config.getoption("--osType")
Затем у меня есть класс теста:
from selenium import webdriver
from pages.home.login_page import LoginPage
import unittest
import pytest
@pytest.mark.usefixtures("oneTimeSetUp", "setUp")
class LoginTests(unittest.TestCase):
@pytest.fixture(autouse=True)
def classSetup(self, ***oneTimeSetUp***):
self.lp = LoginPage(self.driver)
@pytest.mark.run(order=2)
def test_validLogin(self):
self.lp.login("test@email.com", "abcabc")
result = self.lp.verifyLoginSuccessful()
assert result == True
Когда я запускаю тест, я получаю следующую ошибку:
fixture 'oneTimeSetUp' not found
> available fixtures: _UnitTestCase__pytest_class_setup, cache,
capfd, capfdbinary, caplog, capsys, capsysbinary, classSetup,
doctest_namespace, monkeypatch, pytestconfig, record_property,
record_xml_attribute, recwarn, tmp_path, tmp_path_factory, tmpdir,
tmpdir_factory
> use 'pytest --fixtures [testpath]' for help on them.
Я предполагал, что, когда я передаю в одно устройство TimeSetUp на уровне класса, это должно быть включено через autouse = True?