自动化测试与调试技巧
自动化测试
在软件开发过程中,自动化测试是确保代码质量和稳定性的重要手段。下面将介绍如何使用 pytest
进行自动化测试,以及如何选择性地运行测试用例。
准备工作
首先,我们需要安装所需的模块。将以下内容添加到 requirements.txt
文件中:
$ echo "pytest==5.4.1" >> requirements.txt
$ echo "requests==2.23.0" >> requirements.txt
$ echo "responses==0.10.12" >> requirements.txt
$ echo "freezegun==0.3.15" >> requirements.txt
$ pip install -r requirements.txt
同时,你可以从 GitHub 仓库下载测试文件: https://github.com/PacktPublishing/Python-Automation-Cookbook-Second-Edition/tree/master/Chapter12 ,文件结构如下:
├── code
│ ├─