Python 測試入門
Alexander Levin
Data Scientist
命令列介面(CLI):一種使用者介面,你可在終端機輸入文字指令與程式互動。
從 CLI 執行 slides.py 的指令:
pytest slides.py
意義: 「請使用 slides.py 模組中的測試來執行 pytest 框架」
測試輸出:

測試輸出:

測試輸出:

測試輸出:

測試輸出:



在 tests_dir/ 執行所有測試的指令:
pytest tests_dir/
意義: 「請使用 tests_dir 資料夾中找到的所有測試來執行 pytest 框架」。

從 tests_ex.py 執行包含「squared」的測試指令:
pytest tests_ex.py -k "squared"
意義: 「請執行 pytest,僅跑 tests_ex.py 腳本中名稱含 squared 的測試」。
輸出:

pytest 開頭script_name.py 執行單一腳本directory_name/ 執行資料夾內多個腳本-k "keyword_expression"Python 測試入門