Skip to main content

AI-driven test assertion decorator for natural language testing

Project description

shouldpy

"Write your tests the way you always have. Let AI run one final check."

PyPI Python License Downloads

What is this?

A ~200-line decorator that wraps any test function with a natural-language assertion. After the function runs, an LLM inspects all logs, print output, and return values to check whether the condition holds:

  • PASS — passes silently
  • FAIL: reason — raises AssertionError

Does not replace assert. Does not force a return. Does not restructure your test cases. Just one decorator that lets an LLM double-check your work.


Install

pip install shouldpy

Quick start

import should

should.use("openai/gpt-4o-mini", api_key="sk-...")

@should("The log should clearly indicate the order was created successfully")
def test_create_order():
    ...  # your existing test code, unchanged
    logging.info("Order created successfully")
    assert resp.status_code == 200

Run pytest

  • Your existing assert checks the status code
  • AI additionally checks whether logs/output/return value satisfy the natural-language condition

Both must pass.


Supported models

should.use() accepts any model URI supported by chak:

should.use("openai/gpt-4o-mini",        api_key="...")
should.use("anthropic/claude-3-5-sonnet", api_key="...")
should.use("deepseek/deepseek-chat",    api_key="...")
should.use("ollama/llama3",             base_url="http://localhost:11434")

Async support

@should("Async minor registration must be rejected")
async def test_async_register_minor():
    result = await async_register_user("Alice", 15)
    return result

Works out of the box — async functions get a fully async AI call.


Notes

  1. Bring your own API key. shouldpy calls the LLM you configure; it never manages credentials itself.
  2. Non-deterministic. Best suited for exploratory testing, scripting, local spot-checks, and pre-review sanity passes. Do not use as a primary assertion in high-frequency CI pipelines.
  3. Every call hits the model — slow, costs tokens, and may expose data. For sensitive workloads, use a local model (e.g. Ollama).

Feedback

https://github.com/zhixiangxue/should-ai

Issues, PRs, and stars are welcome.


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-2.0.0.tar.gz (6.3 kB view details)

Uploaded Source

Built Distribution

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

shouldpy-2.0.0-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for shouldpy-2.0.0.tar.gz
Algorithm Hash digest
SHA256 d56d90fef531eac2ebb22c742f600cc49a821dfabd5047d626ab532807138562
MD5 bf85de33d1adf95dcf189fa5fbf48442
BLAKE2b-256 90adfb852123d710e93d85f99a264c3f1daea2e354092e854513817df824b0e3

See more details on using hashes here.

Provenance

The following attestation bundles were made for shouldpy-2.0.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-2.0.0-py3-none-any.whl.

File metadata

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

File hashes

Hashes for shouldpy-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 64936af5bfbce3b9253e2148e308fee4b22f3f0032ab62fe72649f6f69a8c825
MD5 818c636b5bac640bc76b248fa3ee6bc6
BLAKE2b-256 ca1bccead0a238621c4e9a4bc6b8f391b09d48e1fc9d5d4e4930c0c95d75d7df

See more details on using hashes here.

Provenance

The following attestation bundles were made for shouldpy-2.0.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