pytest-根據類或函式名選擇用例
您可以使用-k命令列選項來指定一個表示式,該表示式實現了測試名稱上的子字串匹配,而不是-m提供的標記的精確匹配。這使得基於他們的名字選擇測試變得很容易:
Using -k expr
to select tests based on their name¶
You can use the -k
command line option to specify an expression which implements a substring match on the test names instead of the exact match on markers that -m
provides. This makes it easy to select tests based on their names:
$ pytest -v -k http # running with the above defined example module
=========================== test session starts ============================
platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y -- $PYTHON_PREFIX/bin/python3.5
cachedir: .pytest_cache
rootdir: $REGENDOC_TMPDIR, inifile:
collecting ... collected 4 items / 3 deselected
test_server.py::test_send_http PASSED [100%]
================== 1 passed, 3 deselected in 0.12 seconds ==================
And you can also run all tests except the ones that match the keyword:
$ pytest -k "not send_http" -v
=========================== test session starts ============================
platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y -- $PYTHON_PREFIX/bin/python3.5
cachedir: .pytest_cache
rootdir: $REGENDOC_TMPDIR, inifile:
collecting ... collected 4 items / 1 deselected
test_server.py::test_something_quick PASSED [ 33%]
test_server.py::test_another PASSED [ 66%]
test_server.py::TestClass::test_method PASSED [100%]
================== 3 passed, 1 deselected in 0.12 seconds ==================
Or to select “http” and “quick” tests:
$ pytest -k "http or quick" -v
=========================== test session starts ============================
platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y -- $PYTHON_PREFIX/bin/python3.5
cachedir: .pytest_cache
rootdir: $REGENDOC_TMPDIR, inifile:
collecting ... collected 4 items / 2 deselected
test_server.py::test_send_http PASSED [ 50%]
test_server.py::test_something_quick PASSED [100%]
================== 2 passed, 2 deselected in 0.12 seconds ==================
相關文章
- perl根據函式名動態呼叫函式
- 微信小程式中根據字母選擇城市微信小程式
- Shell 根據程式名字找到程式號並kill
- 微信小程式--根據首字母選擇城市微信小程式
- 根據選擇的物料顯示其特性值
- 如何根據自己的需要選擇伺服器配置?伺服器
- 根據應用場景合理選擇工業相機的解析度
- java中介面多個實現類,如何指定實現類,根據子類型別選擇實現方法Java型別
- 如何根據寶塔皮膚引數選擇伺服器伺服器
- 根據開源資料庫選擇合適的工具資料庫
- 根據datetimepicker選擇的日期計算年齡
- ABAP選擇螢幕:根據使用者選擇動態顯示螢幕(轉老宋)
- 根據奧卡姆剃刀原理選擇架構 - Eduards Sizovs架構
- JavaScript 根據type篩選inputJavaScript
- 根據介面動態修改應用底部選單欄
- feof (函式名)函式
- 大資料時代,如何根據業務選擇合適的分散式框架大資料分散式框架
- 根據需要的圖表型別選擇echarts對應的series型別型別Echarts
- 如何根據資料的分佈來選擇ML演算法? - Reddit演算法
- 可以根據心情自動選擇音樂 智慧頭戴耳機Vinci
- 直播軟體開發,Android實現根據程式名殺死特定程式Android
- 根據使用者不同的選擇動態改變程式的標題
- 根據稅碼取得稅率函式函式
- iPhone或將根據地點自動解鎖iPhone
- 如何根據生產環境mysql版本選擇合適的percona xtrabackup版本MySql
- 如何根據需求選擇合適的資料庫管理工具?Navicat OR DBeaver資料庫
- 根據什麼選擇一套適合自己的linux系統?(轉)Linux
- jdbc根據例項名 連線 sql serverJDBCSQLServer
- 002---選擇器(標籤選擇器、類選擇器、id選擇器、偽類選擇器、萬用字元選擇器)字元
- Storm框架:如何根據業務條件選擇不同的bolt進行下發訊息ORM框架
- 選擇介面還是抽象類?---應用例項說明介面與抽象類的應用場合(區別)抽象
- 函式名/函式地址/函式指標函式指標
- EF:根據實體類生成表結構SQLSQL
- PHP利用反射根據類名反向尋找類所在檔案PHP反射
- 根據v$session 之status及logon_time有選擇kill某些session會話SessionGo會話
- js 根據滑鼠拖動(或手機長按)旋轉JS
- DocTemplateTool - 可根據模板生成word或pdf檔案的工具
- activiti 根據 流程例項ID 獲取發起人