TextTest

raw JSON →
4.4.6 verified Fri May 01 auth: no python

TextTest is a tool for text-based Approval Testing, enabling developers to capture and compare output of command-line applications. Current version is 4.4.6, with a stable release cadence.

pip install texttest
error ModuleNotFoundError: No module named 'texttest'
cause The library is not installed or installed in a different Python environment.
fix
Run pip install texttest in the correct environment.
error TypeError: __init__() got an unexpected keyword argument 'texttest_root'
cause The parameter `texttest_root` was renamed to `directory` in version 4.0.
fix
Replace texttest_root with directory in the TextTest constructor.
error AssertionError: Test failed: output differs from approved
cause The actual output does not match the previously approved output, or no approved file exists yet.
fix
If this is the first run, approve the current output by running with --approve flag or using the approve() method. If output changed intentionally, update the approved file.
breaking TextTest 4.x dropped support for Python < 3.9. If upgrading from older versions, ensure your environment uses Python 3.9+.
fix Update Python to 3.9 or higher.
gotcha The `directory` parameter must be an absolute path. Relative paths can cause unexpected behavior or test failures.
fix Always provide an absolute path (e.g., use `os.path.abspath`) for the `directory` argument.
deprecated The `config_file` argument is deprecated in favor of passing configuration via the `config` dict parameter.
fix Replace `config_file='path'` with `config={'key': 'value'}` in the TextTest constructor.

Basic approval test that captures stdout and compares to previously approved output.

from texttest import TextTest
import os

test = TextTest(
    command='echo "Hello, World!"',
    name='hello_world',
    directory='/tmp/texttest_example',
    # For authentication or environment: use os.environ.get('KEY', '')
)
test.run()
assert test.passed
print('Test passed!')