基于 Pytest + Requests + Allure 报告的沪深证券开户接口自动化测试脚本,包含:
- 开户申请(正常 / 必填参数缺失 / Token 无效 / 并发冲突)
- 开户状态查询(审核中 / 失败)
- 数据库校验(MySQL)
- 自动生成美观测试报告
一、项目结构
plaintext
securities_test/ ├── test_account_api.py # 主测试脚本 ├── conftest.py # Pytest 配置、夹具 ├── requirements.txt # 依赖包 └── pytest.ini # 运行配置二、完整代码
1. requirements.txt
txt
pytest>=7.0 requests>=2.31 allure-pytest>=2.13 pymysql>=1.1 faker>=22.02. conftest.py
python
运行
import pytest import requests import pymysql # 接口基础配置 BASE_URL = "https://api.open.secu