pytestfixture在pythonpytes中执行后无法退出测试

2024-05-29 05:56:32 发布

您现在位置:Python中文网/ 问答频道 /正文

我在用下面的固定装置conftest.py对于打开和关闭浏览器: conftest.py公司名称:

@pytest.fixture(scope='session')
def browser():
    print("Setting up webdriver connection...")
    global driver
    if driver is None:
        profile = webdriver.FirefoxProfile()
        profile.accept_untrusted_certs = True
        profile.set_preference("network.proxy.type",1)
        driver = webdriver.Firefox(firefox_profile=profile)
        driver.maximize_window()
        yield driver
        driver.quit()
        print("Webdriver connection closed..")

在我的测试类中,我有以下步骤测试登录:

^{pr2}$

在test_登录之后,我的测试类中还有一个测试步骤:

def test_ppt(a):
    a=12
    print a

问题:我在fixture中遇到错误司机。退出()且浏览器未关闭。在

如果我删除“test_login(self,browser)”之后的“test_ppt(a)”步骤,那么测试运行良好。在

想知道我需要在fixture“browser()”中更新什么以便司机。退出()已执行。在


Tags: pytestbrowserdefdriver步骤浏览器connection

热门问题