Unittest functions isolated.
Project description
FunAlone
A small python library that makes it easy to test a function alone, that is, mocking all dependencies. True unittests, without having to manually look and add every called function to an increasing list of @mock.patch decorators.
Example
Say you have a function named do_a_lot_of_stuff and you want to test it with unittest, only testing the functions code, not the function that it calls within.
def do_a_lot_of_stuff(arg: int):
if arg > 5:
result = do_this(arg)
elif arg < 0:
result = do_that(arg)
else:
result = do_nothing(arg)
return result
In this case you might want to know which external function has been called, depending on the input, without having the code actually call that function (which could have side effects and should have it's own unit tests).
class Test(unittest.TestCase):
def test_do_a_lot_of_stuff_with_5(self):
with IsolatedFunctionClone(
do_a_lot_of_stuff
) as do_a_lot_of_stuff_clone:
# This calls a function clone with an isolated context.
# All external names are mocked.
do_a_lot_of_stuff_clone(5)
# You can access this context later to assert calls,
# And you can use the original functions to do this,
# so it's all refactor-friendly.
do_a_lot_of_stuff_clone.context[do_this].assert_not_called()
do_a_lot_of_stuff_clone.context[do_that].assert_not_called()
do_a_lot_of_stuff_clone.context[do_nothing].assert_called_once()
There are more parameters and ways to use the library, this is only a basic example.
Installation
You can install the latest version with pip:
pip install funalone
Tests
There is a small collection of unittests in the test folder.
You can run them using unittest.
Credits
This project is developed by Borja Martinena (borjamartinena[at]gmail.com).
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 funalone-0.7.0.tar.gz.
File metadata
- Download URL: funalone-0.7.0.tar.gz
- Upload date:
- Size: 6.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
63925c7c43b2d3f10c61d309360b20dc704093c376d0933bd288e6c7f41c928a
|
|
| MD5 |
f943230dd89c9a5d03feebeb818d63c3
|
|
| BLAKE2b-256 |
35e3bb3a99ccef291ed074a989cd3c3907244c040589bac86328a16981764726
|
Provenance
The following attestation bundles were made for funalone-0.7.0.tar.gz:
Publisher:
publish.yml on aafrecct/funalone
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
funalone-0.7.0.tar.gz -
Subject digest:
63925c7c43b2d3f10c61d309360b20dc704093c376d0933bd288e6c7f41c928a - Sigstore transparency entry: 225813983
- Sigstore integration time:
-
Permalink:
aafrecct/funalone@250386d520c114563e1f2042b0bcb7bb67e86447 -
Branch / Tag:
refs/tags/0.7.0-alpha - Owner: https://github.com/aafrecct
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@250386d520c114563e1f2042b0bcb7bb67e86447 -
Trigger Event:
push
-
Statement type:
File details
Details for the file funalone-0.7.0-py3-none-any.whl.
File metadata
- Download URL: funalone-0.7.0-py3-none-any.whl
- Upload date:
- Size: 8.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
56b325009bf9ad42b27bc7bb0d55dcb2d152ff5ae669b7bcb0a127a740b330e2
|
|
| MD5 |
0ac244c1784224609ddfaa84ec547ec9
|
|
| BLAKE2b-256 |
00779a8a61de28746e94900ad7db35a02bfb855b3c98747a3d7fdf45d2368da5
|
Provenance
The following attestation bundles were made for funalone-0.7.0-py3-none-any.whl:
Publisher:
publish.yml on aafrecct/funalone
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
funalone-0.7.0-py3-none-any.whl -
Subject digest:
56b325009bf9ad42b27bc7bb0d55dcb2d152ff5ae669b7bcb0a127a740b330e2 - Sigstore transparency entry: 225813986
- Sigstore integration time:
-
Permalink:
aafrecct/funalone@250386d520c114563e1f2042b0bcb7bb67e86447 -
Branch / Tag:
refs/tags/0.7.0-alpha - Owner: https://github.com/aafrecct
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@250386d520c114563e1f2042b0bcb7bb67e86447 -
Trigger Event:
push
-
Statement type: