[英]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.