基于交互模式的现代化测试自动化框架,支持多种测试场景
Project description
DF Test Framework
企业级 Python 测试自动化框架,支持 HTTP/UI/数据库/消息队列多场景测试
核心特性
- 多协议客户端 — HTTP/GraphQL/gRPC,同步/异步双模式,中间件拦截器链(重试、签名、Bearer Token)
- 异步高性能 —
AsyncHttpClient并发性能提升 10-30 倍,AsyncDatabase/AsyncRedis完整异步支持 - UI 自动化 — Playwright,同步/异步,浏览器会话复用,失败自动截图与诊断
- 数据库访问 — SQLAlchemy 2.0,多方言(MySQL/PostgreSQL/SQLite/MSSQL),Repository + Unit of Work 模式
- 测试数据管线 —
CaseContext[T]+ YAML 驱动参数化,支持 skip/xfail/seed/tags,CLI 精准过滤复现 - 多客户端模型 —
@service_client/@ui_client,多服务/多前端场景下独立管理各自的连接与配置 - CLI 脚手架 —
df-test init一键生成 api/ui/full 项目,内置 Allure + 自动回滚等即用能力 - 可观测性 — OpenTelemetry 链路追踪 + Prometheus 监控 + Allure 报告自动集成
- 消息队列 — Kafka/RabbitMQ/RocketMQ 统一接口
- 存储客户端 — 本地文件 / AWS S3 / 阿里云 OSS
- 脱敏服务 — HTTP/UI/DB 日志中敏感字段自动遮盖,集中配置
- Mock 工具 — HTTP/数据库/Redis/时间 Mock,开箱即用
安装
# 使用 uv(推荐)
uv add df-test-framework
# 使用 pip
pip install df-test-framework
可选依赖(按需安装,核心功能无需额外依赖):
| 依赖组 | 功能 | 安装命令 |
|---|---|---|
ui |
Playwright UI 测试 | uv add "df-test-framework[ui]" |
database-async |
异步数据库驱动(MySQL/PG/SQLite) | uv add "df-test-framework[database-async]" |
database-mssql |
MSSQL 驱动 | uv add "df-test-framework[database-mssql]" |
mq |
消息队列(Kafka + RabbitMQ + RocketMQ) | uv add "df-test-framework[mq]" |
observability |
OpenTelemetry + Prometheus | uv add "df-test-framework[observability]" |
storage |
对象存储(S3 + 阿里云 OSS) | uv add "df-test-framework[storage]" |
crypto |
AES/DES 加解密 | uv add "df-test-framework[crypto]" |
all |
所有可选功能 | uv add "df-test-framework[all]" |
快速开始
脚手架建项目(推荐)
df-test init my-project # API 测试项目
df-test init my-project --type ui # UI 测试项目
df-test init my-project --type full # API + UI 混合
cd my-project && pytest -v
API 测试
from df_test_framework import api_class, BaseAPI
@api_class()
class UserAPI(BaseAPI):
def get_user(self, user_id: int):
return self.get(f"/users/{user_id}")
def test_get_user(user_api: UserAPI): # fixture 由 @api_class 自动注册
response = user_api.get_user(1)
assert response.status_code == 200
异步并发测试
import asyncio
from df_test_framework import AsyncHttpClient
async def test_concurrent():
async with AsyncHttpClient("https://api.example.com") as client:
tasks = [client.get(f"/users/{i}") for i in range(100)]
responses = await asyncio.gather(*tasks)
assert all(r.status_code == 200 for r in responses)
YAML 驱动参数化
# tests/data/login.yaml
tests:
valid_user:
title: "正常登录"
marks: [smoke]
data:
username: admin
password: secret
locked_user:
title: "锁定账号登录失败"
xfail: "已知 Bug #123"
data:
username: locked
password: secret
import pytest
from df_test_framework.testing.data.pipeline import case_dataset, CaseContext
@pytest.mark.parametrize("ctx", case_dataset("tests/data/login.yaml"))
def test_login(ctx: CaseContext, login_api):
response = login_api.login(ctx.data["username"], ctx.data["password"])
assert response.status_code == 200
架构
Layer 4 ─── bootstrap/ # 引导层:Bootstrap、Providers、RuntimeContext
Layer 3 ─── testing/ + cli/ # 门面层:pytest Fixtures、CLI 脚手架
Layer 2 ─── capabilities/ # 能力层:HTTP/UI/DB/MQ/Storage
Layer 1 ─── infrastructure/ # 基础设施:config/logging/events/plugins
Layer 0 ─── core/ # 核心层:纯抽象(无第三方依赖)
横切 ───── plugins/ # 插件:MonitoringPlugin、AllurePlugin
文档
完整文档见项目 GitHub 仓库:
许可证
MIT License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file df_test_framework-4.7.4.tar.gz.
File metadata
- Download URL: df_test_framework-4.7.4.tar.gz
- Upload date:
- Size: 2.5 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
20395dd1394631b51ac8d817331adf1b4918c44c053a361a202a3a73c55c1bca
|
|
| MD5 |
f11f966d250ee05737253b92491c12f0
|
|
| BLAKE2b-256 |
f0db9e5bed247b4ac75d3de16e8c0c7681202fabde2b6e4a887b174f6994f5a6
|
File details
Details for the file df_test_framework-4.7.4-py3-none-any.whl.
File metadata
- Download URL: df_test_framework-4.7.4-py3-none-any.whl
- Upload date:
- Size: 743.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
92c80867be1a323628f3d609448979f3e1af8950d3ade9ba2077d719105543ae
|
|
| MD5 |
344a0b218e0ed4ba0321a4c9224c573c
|
|
| BLAKE2b-256 |
2cbe193d29b1a91da90a97c1b269da4cb65addea868b28e6f175cf36bf886c3c
|