繁体   English   中英

在python pytest中执行后,pytest固定装置无法退出测试

[英]Pytest fixture not able to quit the test after execution in python pytest

我正在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..")

在我的测试课程中,我有以下步骤test_login:

def test_login(self, browser):
        login_page = pagep.LoginPage(browser)
        login_page.login('hptest376@gmail.com', "test12345*")
        login_page.login('user', "pwd")
        assert "Sum" in browser.title

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

def test_ppt(a):
    a=12
    print a

问题:我在driver.quit()的固定装置中遇到错误,并且浏览器没有关闭。

如果我在“ test_login(self,browser)”之后删除“ test_ppt(a)”步骤,则测试运行正常。

想知道我需要在我的装置“ browser()”中更新什么,以便执行driver.quit()。

将灯具的范围更改为“功能”,并且测试现在通过。

@pytest.fixture(scope='function') 
def browser():

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM