Skip to main content

A command line tool to help you shrink failing test data

Project description

Shrinkplz

shrinkplz is a command line tool to help shrink failing test data, similar to git bisect.

shrinkplz can take some input data causing a test failure, and then attempt shrinking it by cutting out lines from the input data until it starts passing.

At the end of the shrinkplz session, you should have a (locally) minimal input data for your test that is still failing.

Installation

This command is available on PyPI

uv tool add shrinkplz

Use Cases

  • Shrinking a failing SQL script, removing irrelevant statements
  • Shrinking a failing CI test run, by removing elements from the test list
  • Shrinking large input data to a program until it starts working again

Quick Start

Start a shrinking session by calling:

shrinkplz start some-test-data

shrinkplz expects a unicode file, and will attempt to shrink it by bisecting the lines themselves.

Once you've started a session, a file called current-input is created. This is the currently shrunk test data.

Once you have started your session, run your test with this test data or otherwise check your conditions:

./run_my_test.py current-input
# ... and then investigating the result

Once you have finished testing the data in current-input, you should mark it with the mark command

# if the test now passes
shrinkplz mark pass 

# if the test is still failing
shrinkplz mark fail

# if the test data is invalid (e.g. the data has become malformed)
shrinkplz mark invalid

Once you mark the result, current-input gets replaced with another candidate for testing.

Each mark gives shrinkplz more information about how it can shrink data.

  • shrinkplz mark fail indicates that current-input is enough to cause the failure, so discards any test data from the original input that isn't in current-input

  • shrinkplz mark pass indicates that current-input is missing the data that causes a failure, so we will restore the chunk of data that we removed

  • shrinplz mark invalid similarly indicates that the chunk of data shouldn't be removed, though without inferring more

After shrinking as much as it can, shrinkplz will write out something like:

Completed our search!
The smallest known data is copied
to current-input

From there, the session is over and current-input represents the result of the search

Script

Just like with git bisect, shrinkplz can be scripted. This is especially valuable for larger pieces of test data, where a shrinking session might require hundreds or thousands of test runs.

shrinkplz script my-test-script my-test-input 

shrinkplz script takes two inputs:

  • a test script, that will be run by shrinkplz to determine how to mark input data.

    The test script's error code determines what the marking is. A return code of 0 means to mark the data as pass, a return code of 125 indicates marking the data as invalid, and any other return code indicates a fail

  • the test input to shrink

The test script is called without arguments, but just like when running a shrinking session manually, current-input will be available as the current input

#!/usr/bin/env bash
# an example shrink script
uv run my-prog.py < current-input

At the end of the shrinkplz script session, current-input will be the shrunk test data

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

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

shrinkplz-0.1.1-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

Details for the file shrinkplz-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: shrinkplz-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 7.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.6

File hashes

Hashes for shrinkplz-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 eb23fd45f59c2c3c1b9a16cc9f7c9ed4f612bc62decfa5513af0cf28349f6e85
MD5 198edb1a74d08b4bee50da7aa9e849e7
BLAKE2b-256 ab7a3f08205165dec7d99355c5a1b4f0ff770c161f53db0b313d9da7e0f73051

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