SuperAPI AI 工具集

pytest-fixture-generator

测试与质量

查看项目

更新于 10-16 04:32

技能介绍

用途:为 Python 项目生成标准化 pytest 测试配置,使项目符合 workspace-hub 测试标准,适用于新项目搭建测试、统一既有测试配置、为数据处理项目添加 fixtures、配置覆盖率要求。不适用于非 Python 项目、测试已完整配置的项目或需要其他测试框架的场景。

前提:Python 3.9+、pytest>=7.4.0、pytest-cov>=4.1.0,且项目具有 src/ 目录结构。

主要能力:生成 pytest.ini(测试路径、文件/类/函数命名规则、unit/integration/slow/llm/scrapy/selenium/database/api/etl 等标记、addopts 含 -v、--strict-markers、--tb=short、--cov=src、--cov-report=term-missing、--cov-fail-under=80、asyncio_mode=auto、timeout=300、警告过滤);生成 conftest.py(路径注入、平台与 OrcaFlex 跳过标记、日志与会话级路径 fixtures、temp_output_dir、sample_dict、sample_list、sample_dataframe、sample_time_series、temp_config、temp_csv、mock_api_response、mock_error_response、自动清理、DataFrame 相等与字典子集断言辅助);生成覆盖率配置(.coveragerc 或 pyproject.toml);生成示例测试模板。

使用方式:命令 /pytest-fixture-generator;可选参数 --markers unit,integration,slow 指定标记,--src-path src/modules 指定模块结构,--coverage 90 指定覆盖率目标。生成后可用 pytest --collect-only 验证发现,pytest -v 执行并查看覆盖率报告。

限制:需已安装 pytest 与 pytest-cov;覆盖率默认阈值 80%,未达标会失败;fixtures 与示例代码需按实际项目调整。其他功能、收费与价格信息暂未提供。