Automatically add context-saving flags to pytest commands to preserve context window space while maintaining essential information.
The Pytest Context Saving feature automatically adds context-saving flags (-r fE and -q) to pytest commands to preserve context window space while maintaining essential information. The proxy recognizes pytest commands and intelligently adds flags only when they're not already present, and skips -q when verbose output is explicitly requested, reducing output while still showing failed tests and errors.
- Automatic Detection: Recognizes pytest commands (
pytest,python -m pytest, etc.) - Smart Flag Addition: Automatically adds
-r fE(show failed tests and errors) and-q(quiet mode) flags, skipping-qwhen verbose output is requested - Conditional Logic: Only adds flags when they're not already present in the command
- Context Preservation: Reduces verbose output to save valuable context window tokens
- Opt-in Feature: Disabled by default, must be explicitly enabled
Pytest context saving is disabled by default and must be explicitly enabled.
--enable-pytest-context-saving # Enable pytest context savingsession:
tool_call_reactor:
pytest_context_saving_enabled: true # Default: falsepython -m src.core.cli --enable-pytest-context-saving# config.yaml
session:
tool_call_reactor:
pytest_context_saving_enabled: trueThen start the proxy:
python -m src.core.cli --config config.yaml# Before context saving:
pytest tests/
# After context saving (automatically modified):
pytest tests/ -r fE -q# If verbose output is requested, skip -q:
pytest tests/ --verbose
# Result: -r fE added, -q skipped
pytest -r fE tests/ --verbose# Before:
python -m pytest tests/unit tests/integration
# After:
python -m pytest tests/unit tests/integration -r fE -qShows only failed tests and errors in the summary:
f: Show failed testsE: Show errors
This eliminates passed tests from the summary, saving tokens.
Quiet mode reduces verbosity:
- Suppresses detailed test collection information
- Reduces progress output
- Shows only essential information
Reduces verbose pytest output to save tokens:
# Without context saving:
pytest tests/ # Shows all test details, collection info, passed tests
# With context saving:
pytest tests/ -r fE -q # Shows only failures and errors, minimal outputStill shows failed tests and error details with -r fE:
# Failed tests are still visible:
FAILED tests/test_example.py::test_function - AssertionError: ...
ERROR tests/test_example.py::test_setup - RuntimeError: ...Quiet mode with -q reduces unnecessary verbosity:
# Without -q: Shows collection details, progress bars, etc.
# With -q: Shows only test results and failuresNo need to manually add flags to every pytest command:
# Agent runs: pytest tests/
# Proxy automatically modifies to: pytest tests/ -r fE -qOnly adds flags when they don't already exist:
# If command already has -r or -q, no modification
pytest tests/ -r fE -q --verbose # No changeFor projects with many tests, context saving dramatically reduces output:
# 100 tests without context saving: 10,000 tokens
# 100 tests with context saving: 1,000 tokens (only failures shown)During iterative development, agents run tests frequently. Context saving reduces cumulative token usage:
# Agent runs tests 20 times during development
# Without context saving: 200,000 tokens total
# With context saving: 20,000 tokens totalIn CI/CD environments, context saving reduces log sizes and focuses on failures:
# CI runs full test suite
# Context-saved output focuses on failures
# Easier to identify and debug issuesFor models with smaller context windows, context saving helps fit more information:
# Model with 8K context window
# Without context saving: Test output fills 6K tokens
# With context saving: Test output uses 600 tokensContext saving not working:
- Verify the feature is enabled (
--enable-pytest-context-savingor config) - Check that pytest commands are being recognized
- Review logs for command modification messages
- Ensure the command format matches expected pytest patterns
Flags not being added:
- Check if flags are already present in the command
- Verify the command is recognized as a pytest command
- Review logs for parsing errors
- Ensure Tool Call Reactor is enabled
Too much output still visible:
- Context saving only adds
-r fEand-qflags (skipping-qwhen verbose output is requested) - If tests have many failures, all failures will still be shown
- Consider combining with Pytest Compression
- Review if additional pytest flags are needed
Missing important information:
- Context saving preserves all failure information
- If specific output is missing, check if it's in the error details
- Review pytest documentation for additional flags
- Consider if
-qis too aggressive for your use case
Performance impact:
- Context saving adds minimal overhead (<1ms per command)
- The benefit (reduced tokens) far outweighs the cost
- Disable if not needed to eliminate any overhead
- Pytest Compression - Compress pytest output to save tokens
- Context Window Enforcement - Enforce per-model context window limits
- Session Management - Intelligent session continuity
- Tool Access Control - Control which tools can be executed