pytest前后置

2021-02-23  本文已影响0人  Lutous

定义fixture:

import pytest
from selenium import webdriver

@pytest.fixture(scope="session")
def open_url():
    driver = webdriver.Chrome()
    driver.get("[http://www.baidu.com](http://www.baidu.com/)")
    yield driver
    driver.quit()

# @pytest.fixture(scope="session")
@pytest.fixture(scope="session", autouse=True)
def refresh_page(open_url):
    yield
    open_url.refresh()
import time
import pytest
# 运行时会自动调用
# @pytest.mark.usefixtures("open_url")
# @pytest.mark.usefixtures("refresh_page")
class TestPytest:
@pytest.mark.smoke
def test_smoke(self):
    print(6*"=", "smoke", 6*"=")
    # open_url.get("[https://www.sina.com.cn](https://www.sina.com.cn/)")
    time.sleep(6)
    print("test_smoke 方法执行了。。。")
    assert 1 == 1
上一篇 下一篇

猜你喜欢

热点阅读