Pytest Fixture-未使用oneTimeSetUp值

时间:2019-03-28 18:02:24

标签: python-3.x selenium-webdriver pytest test-framework

我有一个confp文件

导入pytest 从硒导入webdriver

@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")

然后我有一个Test Fixture类测试:

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.

我假设当我在类级别传递oneTimeSetUp固定装置时,应该通过autouse = True将其包括在内吗?

0 个答案:

没有答案