Skip to main content

AI-driven test assertion decorator for natural language testing

Project description

shouldpy

"已有的测试该怎么写就怎么写,AI 再帮你加一道自然语言安检。"

PyPI Python License Build Status Downloads

❓ 这是什么?

仅200多行的小工具:给现有测试函数加一层 @should("自然语言期望") 装饰器 AI 会在函数跑完后 检查 所有日志、print 输出、返回值,
判断“期望”是否达成 —— PASS 安静通过;FAIL: 原因AssertionError

不替代 assert,不强制 return,不改造testcase
仅用一个装饰器让 LLM 再帮你把把关


⚡️ 安装

pip install shouldpy

# 其他依赖,按需安装
pip install pytest-asyncio
pip install langchain-openai

👨🏻‍💻 例子

from should import should
from langchain_openai import ChatOpenAI

should.use(ChatOpenAI()) # 指定你的llm

@should("日志里应该明确表示下单成功")
def test_create_order():
    ...  # 原来的测试代码,该怎么写怎么写
    logging.info("订单创建成功")
    assert resp.status_code == 200

pytest

  • 原有 assert 检查状态码
  • AI 额外检查日志/输出/返回值里有没有“订单创建成功”之类的输出
    两步都过才算通过。

⚠️ 注意

  1. 需要自备 LangChain 兼容 LLM(OpenAI、DeepSeek、Ollama…)。
  2. 不保证确定性 → 适合教学、脚本、探索式测试、兜底方案,别拿它当核心断言。
  3. 每次都要调模型慢 + 花钱 + 数据安全 → 别塞进高频 CI;本地跑、CR 前抽查更划算;token敏感或者数据敏感的建议用本地模型

🤝 反馈

https://github.com/zhixiangxue/should-ai
issue、PR、star 欢迎!


📄 License

MIT © 2025 zx

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

shouldpy-0.1.0.tar.gz (6.6 kB view details)

Uploaded Source

Built Distribution

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

shouldpy-0.1.0-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

Details for the file shouldpy-0.1.0.tar.gz.

File metadata

  • Download URL: shouldpy-0.1.0.tar.gz
  • Upload date:
  • Size: 6.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for shouldpy-0.1.0.tar.gz
Algorithm Hash digest
SHA256 c6e95f3d1b90206b0ab6cba87e28be1bbb4fc580d0c0027131ca69e7bd4d9293
MD5 7ca422f3e33fe3b57d92feab34336715
BLAKE2b-256 308bda9691a4fa965a10f4a4f242e70a5ed1cf629c7f72500bca1d9ca568bca7

See more details on using hashes here.

Provenance

The following attestation bundles were made for shouldpy-0.1.0.tar.gz:

Publisher: publish.yml on zhixiangxue/should-ai

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file shouldpy-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: shouldpy-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for shouldpy-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9bfaee0efd9a5c714480e773374976959ed5f253a8cc8665ddb05dd596db971f
MD5 8e3ca022311e957fe6717ace911e4c56
BLAKE2b-256 7a784e7db330dea4e180c4e93a27f8d6188bf13f943a0e59afe895aafb950925

See more details on using hashes here.

Provenance

The following attestation bundles were made for shouldpy-0.1.0-py3-none-any.whl:

Publisher: publish.yml on zhixiangxue/should-ai

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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