1. 程式人生 > 其它 >023、命令列引數 和 pytest.ini 配置

023、命令列引數 和 pytest.ini 配置

參考資料:

  1、內建 request :https://www.cnblogs.com/yoyoketang/p/14041751.html;

  

一、內建request

  a、request.param 前面講fixture引數化的時候,有接觸到 "request.param" 用於獲取測試的請求引數;

以下示例:

import pytest

user_data =[
    {'name': 'sky', 'pwd': 123},
    {'name': 'Jack', 'pwd': 250}
]


@pytest.fixture(params=user_data)
def
login(request): user = request.param print(f"\n使用者名稱是:{user['name']},密碼是:{user['pwd']}") return user def test_login_pass(login): user = login print(f"\n======名字是:{user['name']},密碼是:{user['pwd']}=======")
View Code

執行結果如下:

D:\SkyWorkSpace\WorkSpace\Pytest\Temp\day15\cc>pytest -sv
================================================= test session starts ================================================= platform win32 -- Python 3.8.6, pytest-5.4.3, py-1.10.0, pluggy-0.13.1 -- c:\skyworkspace\worktools\python\python38\python.exe cachedir: .pytest_cache metadata: {'Python': '3.8.6', 'Platform
': 'Windows-10-10.0.19041-SP0', 'Packages': {'pytest': '5.4.3', 'py': '1.10.0', 'pluggy': '0.13.1'}, 'Plugins': {'allure-pytest': '2.9.43', 'html': '2.1.1', 'metadata': '1.11.0'}, 'JAVA_HOME': 'C:\\SkyWorkSpace\\WorkTools\\Java\\jdk1.8\\jdk1.8.0_271'} rootdir: D:\SkyWorkSpace\WorkSpace\Pytest\Temp\day15\cc plugins: allure-pytest-2.9.43, html-2.1.1, metadata-1.11.0 collected 2 items test_cc.py::test_login_pass[login0] 使用者名稱是:sky,密碼是:123 ======名字是:sky,密碼是:123======= PASSED test_cc.py::test_login_pass[login1] 使用者名稱是:Jack,密碼是:250 ======名字是:Jack,密碼是:250======= PASSED ================================================== 2 passed in 0.03s ================================================== D:\SkyWorkSpace\WorkSpace\Pytest\Temp\day15\cc>
View Code