fixtrue基礎之ids引數
一、 ids引數是什麼?
· ids引數是配合fixture的params引數用的,如果沒有設定params引數,那麼ids毫無意義;
· ids引數是給每一項params引數設定自定義名稱用的;
· params引數值包含的列表有多少項值,那麼ids引數就必須對應有多少項值。
二、 ids引數應用
· 2.1 沒帶ids引數的示例
import pytest
user_list = ['xiaoming','xiaohong','xiaoli']
@pytest.fixture(params=user_list)
def setUp(request):
return request.param
def testadd(setUp):
print('\n使用者名稱:' + str(setUp))
assert 1
if __name__=='__main__':
pytest.main(["-v"]) #-v引數:輸出用例詳細的執行資訊
以上程式碼執行結果:
/usr/local/bin/python3.8
/Users/lanyin/PycharmProjects/newdream/app_demo/blog_demo/test_demo_01.py
============================= test session starts ==============================
platform darwin -- Python 3.8.2, pytest-5.4.0, py-1.8.1, pluggy-0.13.1 --
/usr/local/bin/python3.8
mcachedir: .pytest_cache metadata: {'Python': '3.8.2', 'Platform': 'macOS-10.15.3-x86_64-i386-64bit', 'Packages':
{'pytest': '5.4.0', 'py': '1.8.1', 'pluggy': '0.13.1'}, 'Plugins': {'ordering': '0.6', 'html': '2.1.0', 'allure-pytest': '2.8.11', 'metadata': '1.8.0'}, 'JAVA_HOME':
'/Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/Home'}
rootdir: /Users/liuqingjun/PycharmProjects/newdream/app_demo, inifile: pytest.ini
plugins: ordering-0.6, html-2.1.0, allure-pytest-2.8.11, metadata-1.8.0
collecting ... collected 3 items
test_demo_01.py::testadd[xiaoming] PASSED [ 33%]
test_demo_01.py::testadd[xiaohong] PASSED [ 66%]
test_demo_01.py::testadd[xiaoli] PASSED [100%]
============================== 3 passed in 0.03s ===============================
· 2.2 帶正主 ids引數 的示例
import pytest
user_list = ['xiaoming','xiaohong','xiaoli']
param_name = ['first_group_data','second_group_data','third_group_data']
@pytest.fixture(params=user_list,ids=param_name)
def setUp(request):
return request.param
def testadd(setUp):
print('\n使用者名稱:' + str(setUp))
assert 1
if __name__=='__main__':
pytest.main(["-v"]) #-v引數:輸出用例詳細的執行資訊
以上程式碼執行結果:
/usr/local/bin/python3.8
/Users/lanyin/PycharmProjects/newdream/app_demo/blog_demo/test_demo_01.py
============================= test session starts ==============================
platform darwin -- Python 3.8.2, pytest-5.4.0, py-1.8.1, pluggy-0.13.1 --
/usr/local/bin/python3.8
cachedir: .pytest_cache
metadata: {'Python': '3.8.2', 'Platform': 'macOS-10.15.3-x86_64-i386-64bit', 'Packages': {'pytest': '5.4.0', 'py': '1.8.1', 'pluggy': '0.13.1'}, 'Plugins': {'ordering': '0.6', 'html': '2.1.0', 'allure-pytest': '2.8.11', 'metadata': '1.8.0'}, 'JAVA_HOME':
'/Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/Home'}
rootdir: /Users/liuqingjun/PycharmProjects/newdream/app_demo, inifile: pytest.ini
plugins: ordering-0.6, html-2.1.0, allure-pytest-2.8.11, metadata-1.8.0 collecting ... collected 3 items
test_demo_01.py::testadd[first_group_data] PASSED [ 33%]
test_demo_01.py::testadd[second_group_data] PASSED [ 66%]
test_demo_01.py::testadd[third_group_data] PASSED [100%]
============================== 3 passed in 0.02s ===============================
上述兩個例項小結:
· 可以從程式碼的輸出結果看出 ids引數的作用;
· 筆者這裡認為其實設定與否對 測試 本身沒有多大影響。
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/69940641/viewspace-2910697/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- fixtrue基礎之scope引數
- fixtrue基礎之name引數
- fixtrue基礎之autouse引數
- fixtrue基礎之params引數實現簡單引數化
- python基礎之 函式的引數Python函式
- fixtrue基礎之測試初始化及測試後清理操作
- Python基礎(11):引數Python
- Oracle引數檔案基礎Oracle
- java基礎的學習之引數的變化使用Java
- Mysql 效能優化--基礎引數MySql優化
- [java基礎]之變數Java變數
- 數學基礎之微積分
- Jmeter基礎004----增加引數化JMeter
- 函式基礎和函式引數函式
- CSS3-陰影引數基礎CSSS3
- Mysql 效能最佳化--基礎引數MySql
- 『忘了再學』Shell基礎 — 16、位置引數變數變數
- 數學基礎之機率
- 數學基礎之線性代數
- c#基礎-5.變長引數和引數預設值C#
- JUnit5學習之六:引數化測試(Parameterized Tests)基礎Zed
- 【ES6基礎】預設引數值
- Spring WebFlux 基礎教程:引數校驗SpringWebUX
- Thinkphp5基礎——10 請求引數PHP
- Oracle基礎 07 引數檔案 pfile/spfileOracle
- Java 基礎 之 算數運算子Java
- java基礎(九) 可變引數列表介紹Java
- stylus_基礎語法(引數/function/運算子)Function
- oracle基礎筆記之第一篇 DBAtools和初始化引數Oracle筆記BAT
- Go 之基礎速學 (五) golang 裡函式以及函式之間引數的傳遞Golang函式
- Linux基礎之Shell與變數Linux變數
- Matplotlib基礎:subplot多子圖index引數解釋Index
- JavaWeb基礎-Request物件接收表單請求引數JavaWeb物件
- 『動善時』JMeter基礎 — 24、JMeter中使用“使用者引數”實現引數化JMeter
- 前端基礎之jQuery基礎前端jQuery
- mybatis基礎03(介面中的多個引數處理)MyBatis
- 基礎知識3——資料庫初始化引數資料庫
- Java逆向基礎之靜態變數存取Java變數