Pytest測試框架(一):pytest安裝及用例執行
阿新 • • 發佈:2021-01-01
PyTest是基於Python的開源測試框架,語法簡單易用,有大量的外掛,功能非常多。自動檢測測試用例,支援引數化,跳過特定用例,失敗重試等功能。
# 安裝
```python
pip install -U pytest # 安裝
pytest --version # 檢視版本
pytest -h # 檢視幫助資訊
```
# 用例識別
- pytest識別檔名為test\_*.py或者*\_test.py的測試檔案
- 測試檔案中可以在Test\*類中寫測試用例(測試用例以test_\*開頭,並且測試類不能有__init__方法)
- 不在Test*類中的test_*用例也可以被識別到。
識別包含“add”的用例:
`pytest -k "add" --collect-only`
```shell
(base) D:\ProgramWorkspace\TestingDemo>pytest -k "add" --collect-only
============================================== test session starts ==============================================
platform win32 -- Python 3.7.6, pytest-5.3.5, py-1.8.1, pluggy-0.13.1
rootdir: D:\ProgramWorkspace\TestingDemo
plugins: hypothesis-5.5.4, arraydiff-0.3, astropy-header-0.1.2, doctestplus-0.5.0, openfiles-0.4.0, remotedata-0.3
.2
collected 20 items / 11 deselected / 9 selected