Python 测试入门
Alexander Levin
Data Scientist
命令行界面(CLI):通过在终端输入文本命令与程序交互的用户界面。
从 CLI 运行 slides.py 的命令:
pytest slides.py
含义:"请运行 pytest,使用 slides.py 模块中的测试"
测试输出:

测试输出:

测试输出:

测试输出:

测试输出:



运行 tests_dir/ 中所有测试的命令:
pytest tests_dir/
含义:"请运行 pytest,执行 tests_dir 文件夹中找到的所有测试"。

从 tests_ex.py 中运行包含"squared"的测试:
pytest tests_ex.py -k "squared"
含义:"请运行 pytest,只执行 tests_ex.py 中名称包含 squared 的测试"。
输出:

pytest 开头script_name.pydirectory_name/-k "keyword_expression"Python 测试入门