Skip to main content

基于交互模式的现代化测试自动化框架,支持多种测试场景

Project description

DF Test Framework

企业级 Python 测试自动化框架,支持 HTTP/UI/数据库/消息队列多场景测试

PyPI version Python License


核心特性

  • 多协议客户端 — 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

df_test_framework-4.7.5.tar.gz (2.5 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

df_test_framework-4.7.5-py3-none-any.whl (743.2 kB view details)

Uploaded Python 3

File details

Details for the file df_test_framework-4.7.5.tar.gz.

File metadata

  • Download URL: df_test_framework-4.7.5.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

Hashes for df_test_framework-4.7.5.tar.gz
Algorithm Hash digest
SHA256 4105f29548a1a9bd1bfeff9edc0589167df9b56e4cb82c4ccf2bbca28f11e781
MD5 94eb71e1576e373e3c9756c29cd2c0b1
BLAKE2b-256 94673c37d9f9011a19f0e5d0e99ac0f86496c9328a9d244fe7c2ed167b5fb467

See more details on using hashes here.

File details

Details for the file df_test_framework-4.7.5-py3-none-any.whl.

File metadata

File hashes

Hashes for df_test_framework-4.7.5-py3-none-any.whl
Algorithm Hash digest
SHA256 c0c7ea9324ea2b456a9dd9305a40a5a35c3592415dd18ee034cf0bdcf1e6bf2f
MD5 393144a59fcf6c69e70781ec26c29ec9
BLAKE2b-256 47c176cafcd0bbbe29ee6c1ab2845e1006d53286654d5b843e84547790131009

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page