Skip to main content

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:

            # This calls a function clone with an isolated context.
            # All external names are mocked.
            do_a_lot_of_stuff(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.context[do_this].assert_not_called()
            do_a_lot_of_stuff.context[do_that].assert_not_called()
            do_a_lot_of_stuff.context[do_nothing].assert_called_once()

There are more parameters and ways to use the library, this is only a basic example.

Project details


Download files

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

Source Distribution

funalone-0.6.0.tar.gz (6.0 kB view details)

Uploaded Source

Built Distribution

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

funalone-0.6.0-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

Details for the file funalone-0.6.0.tar.gz.

File metadata

  • Download URL: funalone-0.6.0.tar.gz
  • Upload date:
  • Size: 6.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for funalone-0.6.0.tar.gz
Algorithm Hash digest
SHA256 d752281e3a8c1771838dc41ed3253d745cadd133dcbe6895055dc66672e62979
MD5 e81434897916df2e6c95df4bf68f3f8c
BLAKE2b-256 4ce507baddca06fb8869d2d7b31e0cb7cdf953da7810790cc276989f32bd7270

See more details on using hashes here.

Provenance

The following attestation bundles were made for funalone-0.6.0.tar.gz:

Publisher: publish.yml on aafrecct/funalone

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file funalone-0.6.0-py3-none-any.whl.

File metadata

  • Download URL: funalone-0.6.0-py3-none-any.whl
  • Upload date:
  • Size: 7.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for funalone-0.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 defe8adb956c076a73f36f9bc169b8a838a02e7de5b8e55b291773898a5dc0f2
MD5 0013d6c0dc1ca5ef2ff987ad14982c0e
BLAKE2b-256 39fac9edf64c3ffb72147e7eee049c9bf0bf8a9b01a70af23bbd5b0daf1a788d

See more details on using hashes here.

Provenance

The following attestation bundles were made for funalone-0.6.0-py3-none-any.whl:

Publisher: publish.yml on aafrecct/funalone

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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