AI-driven test assertion decorator for natural language testing
Project description
shouldpy
"已有的测试该怎么写就怎么写,AI 再帮你加一道自然语言安检。"
❓ 这是什么?
仅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 额外检查日志/输出/返回值里有没有“订单创建成功”之类的输出
两步都过才算通过。
⚠️ 注意
- 需要自备 LangChain 兼容 LLM(OpenAI、DeepSeek、Ollama…)。
- 不保证确定性 → 适合教学、脚本、探索式测试、兜底方案,别拿它当核心断言。
- 每次都要调模型 → 慢 + 花钱 + 数据安全 → 别塞进高频 CI;本地跑、CR 前抽查更划算;token敏感或者数据敏感的建议用本地模型
🤝 反馈
https://github.com/zhixiangxue/should-ai
issue、PR、star 欢迎!
📄 License
MIT © 2025 zx
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 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c6e95f3d1b90206b0ab6cba87e28be1bbb4fc580d0c0027131ca69e7bd4d9293
|
|
| MD5 |
7ca422f3e33fe3b57d92feab34336715
|
|
| BLAKE2b-256 |
308bda9691a4fa965a10f4a4f242e70a5ed1cf629c7f72500bca1d9ca568bca7
|
Provenance
The following attestation bundles were made for shouldpy-0.1.0.tar.gz:
Publisher:
publish.yml on zhixiangxue/should-ai
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
shouldpy-0.1.0.tar.gz -
Subject digest:
c6e95f3d1b90206b0ab6cba87e28be1bbb4fc580d0c0027131ca69e7bd4d9293 - Sigstore transparency entry: 533624779
- Sigstore integration time:
-
Permalink:
zhixiangxue/should-ai@110fda396c84519e2bbd0e5d6c2f2b529894e373 -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/zhixiangxue
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@110fda396c84519e2bbd0e5d6c2f2b529894e373 -
Trigger Event:
push
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9bfaee0efd9a5c714480e773374976959ed5f253a8cc8665ddb05dd596db971f
|
|
| MD5 |
8e3ca022311e957fe6717ace911e4c56
|
|
| BLAKE2b-256 |
7a784e7db330dea4e180c4e93a27f8d6188bf13f943a0e59afe895aafb950925
|
Provenance
The following attestation bundles were made for shouldpy-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on zhixiangxue/should-ai
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
shouldpy-0.1.0-py3-none-any.whl -
Subject digest:
9bfaee0efd9a5c714480e773374976959ed5f253a8cc8665ddb05dd596db971f - Sigstore transparency entry: 533624789
- Sigstore integration time:
-
Permalink:
zhixiangxue/should-ai@110fda396c84519e2bbd0e5d6c2f2b529894e373 -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/zhixiangxue
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@110fda396c84519e2bbd0e5d6c2f2b529894e373 -
Trigger Event:
push
-
Statement type: