Automatically generate arguments of Python functions.
Project description
ExploTest
ExploTest is a tool that turns exploratory test runs into unit tests by capturing and serializing run-time arguments.
By adding the @explore decorator to any function, ExploTest automatically generates unit tests with assertions based
on the previous execution values.
Installation
pip install ExploTest
Local Installation
python3 -m pip install -e <path/to/explotest>
Usage
On any function or method (except for closures), add the @explore decorator. When this function (the
function-under-test or FUT) is called at runtime, a
unit test will be generated and saved in same directory as the file of the FUT.
The @explore decorator accepts two optional parameters, mode and explicit_record.
Configuration
mode determines how the run-time arguments are reconstructed in the unit test:
- Setting this to
"p"or"pickle"results in ExploTest "pickling" (a Python specific binary serialization) each argument into a file, then loading this file in the unit test. ExploTest uses the dill library for pickling, which enables support for function arguments among others. However, objects that cannot be pickled ( e.g., Pandas DataFrames) cannot be saved. This is the default behaviour. - Setting this to
"a"results in ExploTest attempting to reconstruct the parameter by creating a new object and setting all its fields to the runtime argument. For example, when running the code
class Bar:
x = 1
@explore(mode="a")
def baz(b):
return
baz(Bar())
the unit test
@pytest.fixture
def generate_b():
clone_b = scratchpad.Bar.__new__(scratchpad.Bar)
setattr(clone_b, 'x', 1)
return clone_b
def test_baz(generate_b):
b = generate_b
return_value = scratchpad.baz(b)
assert return_value is None
is generated. This will not work for some objects, namely ones that are "more" than just a collection of fields or have
fields that cannot be setattr'd. In this case,
ExploTest will try to fall back on pickling.
explicit_record determines when ExploTest generates a unit test. By default, this is False and so ExploTest
generates a unit test everytime
a function with the @explore decorator is called. However, this may become unwieldy if the function is called many
times and
only certain tests are desired. By setting explicit_record to True in a function, a unit test will only be created
if the function body calls
explotest_record(). Note that due to implementation details, this is not thread safe.
For example,
@explore(explicit_record=True)
def fib(n):
if n <= 1:
explotest_record()
return 1
return fib(n - 1) + fib(n - 2)
A unit test will only be generated for when n <= 1.
Development Setup
Create a venv, then install pip-tools. Run pip-compile as specified.
python3 -m venv .venv
pip install pip-tools
pip-compile -o requirements.txt ./pyproject.toml
pip install -r requirements.txt
Copyright
ExploTest is free and open source software, licensed under the GNU LGPL v3 or any later version.
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 explotest-1.0.1.tar.gz.
File metadata
- Download URL: explotest-1.0.1.tar.gz
- Upload date:
- Size: 25.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7a35452d181615d53ae8d9cb436b5f7d3ffb66ce46ae12888bb0874e245622b0
|
|
| MD5 |
4f375f70f273e962e146510797358fc9
|
|
| BLAKE2b-256 |
e821a249c97b49eda62f05d412d79166146d7677d5d2bbc90b9bc366fad3f796
|
Provenance
The following attestation bundles were made for explotest-1.0.1.tar.gz:
Publisher:
python-publish.yml on kliu04/explotest
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
explotest-1.0.1.tar.gz -
Subject digest:
7a35452d181615d53ae8d9cb436b5f7d3ffb66ce46ae12888bb0874e245622b0 - Sigstore transparency entry: 704431750
- Sigstore integration time:
-
Permalink:
kliu04/explotest@a4b45d27dbf6948a1e5c163c5e3832e36d0f816f -
Branch / Tag:
refs/tags/1.0.1 - Owner: https://github.com/kliu04
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@a4b45d27dbf6948a1e5c163c5e3832e36d0f816f -
Trigger Event:
release
-
Statement type:
File details
Details for the file explotest-1.0.1-py3-none-any.whl.
File metadata
- Download URL: explotest-1.0.1-py3-none-any.whl
- Upload date:
- Size: 24.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dcd1f8b0291add2f9dd8c6e313a023157d4b806efad46fa17ef485c98187e4c3
|
|
| MD5 |
4606744ec6959424f753c0cf4b5b7bf2
|
|
| BLAKE2b-256 |
3eb8f59df1f21ba2b2cff21c56aa4ca33e7e17a796681a13ed6cc8c92bde3294
|
Provenance
The following attestation bundles were made for explotest-1.0.1-py3-none-any.whl:
Publisher:
python-publish.yml on kliu04/explotest
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
explotest-1.0.1-py3-none-any.whl -
Subject digest:
dcd1f8b0291add2f9dd8c6e313a023157d4b806efad46fa17ef485c98187e4c3 - Sigstore transparency entry: 704431779
- Sigstore integration time:
-
Permalink:
kliu04/explotest@a4b45d27dbf6948a1e5c163c5e3832e36d0f816f -
Branch / Tag:
refs/tags/1.0.1 - Owner: https://github.com/kliu04
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@a4b45d27dbf6948a1e5c163c5e3832e36d0f816f -
Trigger Event:
release
-
Statement type: