Skip to main content

Generate adversarial pytest tests using LLM

Project description

pytest-adversarial

PyPI version Python License: MIT

LLM-powered adversarial test generation for Python using Quality-Diversity algorithms.

Installation

pip install pytest-adversarial

Quick Example

Test a JSON parser for edge cases:

# target.py
import json

def parse_json(text: str) -> dict:
    """Parse JSON string."""
    return json.loads(text)

Run adversarial testing:

pytest-adversarial examples/json_parser/target.py --rounds 10

The tool will automatically:

  • Generate adversarial test inputs using LLMs
  • Find edge cases that crash your code
  • Evolve attacks using Quality-Diversity search
  • Report robustness metrics and discovered vulnerabilities

Sample output:

Round 5/10 | Robustness: 73.2% | Attacks: 42 | Types: 8
Found: malformed_unicode, extreme_nesting, special_chars...

Documentation

For detailed usage, examples, and advanced features, visit: github.com/nulone/pytest-adversarial

Requirements

  • Python 3.10+
  • OpenAI API key (set OPENROUTER_API_KEY environment variable)

License

MIT License - see GitHub repository for details.

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

pytest_adversarial-0.1.0.tar.gz (38.5 kB view details)

Uploaded Source

Built Distribution

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

pytest_adversarial-0.1.0-py3-none-any.whl (37.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pytest_adversarial-0.1.0.tar.gz
  • Upload date:
  • Size: 38.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.12

File hashes

Hashes for pytest_adversarial-0.1.0.tar.gz
Algorithm Hash digest
SHA256 2bd9c8d78e5df84da87fa5521c7c5dd92ff3b81e271ae3372a9bf9cd1cdb40f3
MD5 fce7038c797376430482aa7f392b1b82
BLAKE2b-256 804b0ce3183589a9ee3dc89c17d65704c12360b9ee6788fdbaa51017ba6220e2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytest_adversarial-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5e065064035171b55ba95ae6cebc6589d4465bc0e2f46ca26e61f679e446f587
MD5 c0c22e8649cdbe6864bf3a857b88f017
BLAKE2b-256 a8ac83a7d64f1d4f9fcbc13f13adcfe57e5e4fb194700b4cc8c32befa71aff6b

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