pytest3-命令行選項


1.pytest -h 查看pytest常用命令

E:\myproj\pytest_demo>pytest -h
usage: pytest [options] [file_or_dir] [file_or_dir] [...]

positional arguments:
  file_or_dir

general:
  -k EXPRESSION         only run tests which match the given substring
                        expression. An expression is a python evaluatable
                        expression where all names are substring-matched
...以下略

2.pytest -vs(-v是啰嗦模式,啥信息都顯示;-s允許測試運行時輸出任何符合標准的輸出流信息,例如代碼里面的print)

執行結果:
E:\myproj\pytest_demo>pytest -vs
================================================================================== test session starts ==================================================================================
platform win32 -- Python 3.6.5, pytest-5.1.2, py-1.8.0, pluggy-0.12.0 -- e:\soft\python\python36\python.exe
cachedir: .pytest_cache
rootdir: E:\myproj\pytest_demo, inifile: pytest.ini, testpaths: ./testcases
collected 9 items                                                                                                                                                                        

testcases/test_02.py::test_1 FAILED              # FAILED指測試失敗
testcases/test_02.py::test_2 b
PASSED  # 指測試通過
testcases/test_02.py::test_3 c
PASSED
testcases/test_fix.py::Test1::test_s1[\u6d4b\u8bd5-\u6d4b\u8bd5] 測試
PASSED
testcases/test_fix.py::Test1::test_s2 用例2:不需要登錄,操作222
PASSED
testcases/test_fix.py::Test1::test_s3 登錄系統
用例3:登錄之后其它動作333
PASSED
testcases/test_fix.py::Test2::test_s4 登錄系統
用例4:登錄之后其它動作444
PASSED
testcases/test_fix.py::Test2::test_s5 用例5:不需要登錄,操作555
PASSED
testcases/test_fix.py::Test2::test_s6 用例6:登錄之后其它動作666
PASSED

======================================================================================= FAILURES ========================================================================================
________________________________________________________________________________________ test_1 _________________________________________________________________________________________

    def test_1():
        a = 2
>       assert a == 1
E       assert 2 == 1
E         -2
E         +1

testcases\test_02.py:9: AssertionError
============================================================================== 1 failed, 8 passed in 0.29s ==============================================================================

 3.pytest --lf --ff

--lf, --last-failed rerun only the tests that failed at the last run (or          # 運行上次失敗的用例,如果沒有失敗會重新跑
all if none failed)
--ff, --failed-first run all tests but run the last failures first. This
may re-order tests and thus lead to repeated fixture
setup/teardown

4.pytest -x : exit instantly on first error or failed test

5.pytest -q 簡化輸出信息

6.pytest --tb=no 關閉錯誤信息回溯 argument --tb: (choose from 'short', 'no', 'line')

7.pytest --markers :查看所有markers

8.pytest -m “mark標記名”:運行指定標記的測試用例

9.pytest -k

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM