A pytest plugin to sanitize output for LLMs (personal tool, no warranty or liability)
Project description
pytest-sanitizer - Pytest Output Sanitizer for LLMs
A pytest plugin that sanitizes test output to prevent LLMs from seeing expected values in assertion errors.
DISCLAIMER
USE AT YOUR OWN RISK: This tool is provided "AS IS" without any warranties or guarantees of any kind, express or implied. The author takes NO RESPONSIBILITY and accepts NO LIABILITY for any issues, failures, or damages that may arise from using this tool.
NO WARRANTY: There is absolutely no guarantee that this tool will work correctly or continue to work in the future. It may fail to sanitize certain outputs, miss assertion errors, or interfere with your test runs in unexpected ways.
NO SUPPORT: This is a personal tool not intended for production use. Issues, bugs, or compatibility problems will likely not be addressed.
If you use this tool and miss failing tests or if it causes any other problems in your testing process, that's entirely your responsibility.
Maintenance Status
Personal Tool: This package is primarily developed for personal use and not actively maintained for the broader community. Feel free to use it, but be aware that issues and pull requests might not be addressed.
Problem
LLMs sometimes "cheat" by looking at the expected values in assertion errors. For example, given an error like:
FAILED tests/test_utils.py::test_format_duration - AssertionError: assert '1d' == '1d 2h'
An LLM might modify the test to match the result given by the code, or worse, hardcode the expected result.
Solution
pytest-sanitizer hooks into pytest's reporting system and sanitizes the output, removing the expected values from assertion errors while maintaining:
- Error tracebacks
- Colorized output
- Enough context to debug the issue
Installation
For local installation from GitHub:
# Clone the repository
git clone https://github.com/username/pytest-sanitizer.git
# Install in development mode
cd pytest-sanitizer
pip install -e .
Or install from PyPI:
pip install pytest-sanitizer
Usage
After installation, the plugin is automatically enabled when running pytest:
pytest tests/
The output will be sanitized to hide expected values in assertion errors.
You can also use the provided command-line tool:
pytest-sanitizer tests/
Disabling Sanitization
For debugging or when you need to see the actual expected values, you can disable sanitization:
# Using pytest directly
pytest tests/ --no-sanitize # or the shorter --ns flag
# Using the command-line tool
pytest-sanitizer tests/ --no-sanitize # or --ns
Example
Original pytest output:
FAILED tests/test_utils.py::test_format_duration - AssertionError: assert '1d' == '1d 2h'
Sanitized output:
FAILED tests/test_utils.py::test_format_duration - AssertionError: assert '1d' == [SANITIZED]
[NOTE: This output has been sanitized to prevent revealing expected values. You need to determine whether the issue is in the test or the implementation.]
Demo
Run the included demo script to see how the sanitizer transforms assertion messages:
python demo.py
License
MIT License
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 pytest_sanitizer-0.1.0.tar.gz.
File metadata
- Download URL: pytest_sanitizer-0.1.0.tar.gz
- Upload date:
- Size: 11.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a2067096d64c71ce94b0d913558d72f497f420b646a177cd1829e8ab05654f56
|
|
| MD5 |
cd3cfcbedcaa1c452ccc215531a20359
|
|
| BLAKE2b-256 |
8f8987410146d77883ff7948db4da383eaee5ed68174cd833827455c43442ff4
|
File details
Details for the file pytest_sanitizer-0.1.0-py3-none-any.whl.
File metadata
- Download URL: pytest_sanitizer-0.1.0-py3-none-any.whl
- Upload date:
- Size: 14.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6268057736796e4e3c5d1d3767c6212b5ca9b7bac89cbb6a1575cd9d40d6c7d7
|
|
| MD5 |
d951dc12d1c14ce7865cdecd809bd99c
|
|
| BLAKE2b-256 |
3a01e766e8358382f4d9901ac2e9e036e495ce76d54e11e8c55ac5c7b4f3fa8a
|