conftest.py文件:
import pytest
from selenium import webdriver
@pytest.fixture(scope='module')
# @pytest.fixture(scope='module', params=["[http://www.baidu.com](http://www.baidu.com/)"]) --- fixture的参数化
def open_url(request):
url = request.param
driver = webdriver.Chrome()
driver.get(url)
return driver
test_*.py文件:
- indirect=True,把open_url当做函数去执行
class TestPytest:
@pytest.mark.smoke
# @pytest.mark.usefixtures("open_url")
@pytest.mark.parametrize("open_url", ["[https://www.sina.com.cn](https://www.sina.com.cn/)"], indirect=True) # --- mark.parametrize参数化
def test_smoke(self, open_url):
print(6*"=", "smoke", 6*"=")
open_url.quit()
time.sleep(6)
print("test_smoke 方法执行了。。。")
assert 1 == 1