Skip to main content

Python String Test Runner

Unittest wrapper that runs tests contained in strings.

Setup

pip install strtest

Running tests

run_str_test.py [-f function_name] file_with_the_function.py test_file.py

There is an example here

Test files

Test files must contain a class called TestCase that inherits from str_test.TestCaseWrapper. All methods with names starting with test_ will be considered tests.

from strtest import str_test

class TestCase(str_test.TestCaseWrapper):
    TIMEOUT = 1  # In seconds

    def test_1(self):
        result = self.function(1, 2)
        self.assertEqual(3, result, msg=f'Results are not equal. Expected: 3. Got: {result}')

    def test_2(self):
        self.assertTrue(False, msg='This will always fail')

Example

Assume you have the test file all_tests.py with the code above and want to test the file my_implementation.py containing the following code:

def add_numbers(a, b):
    return a + b

You can run the tests with:

run_str_test.py -f add_numbers my_implementation.py all_tests.py

Metadata

Release files for strtest 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for strtest 0.1.0
File Size Uploaded
strtest-0.1.0.tar.gz 7.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for strtest 0.1.0
File Interpreter ABI Platform
strtest-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 17.4 kB

Release files / strtest-0.1.0.tar.gz

Download URL strtest-0.1.0.tar.gz
Size 7.9 kB
Tags Source
SHA-256 checksum
How to use checksums
f817f9703d4c0fb9f56a26c6ee7ebf32e42c39dbc3215121d95d80efa34fe915
BLAKE2b-256 checksum
How to use checksums
7a22060a6100ec67d0004862ff2132ff3547e3b546787d0788b4f76567e0e852
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.7.1

Release files / strtest-0.1.0-py3-none-any.whl

Download URL strtest-0.1.0-py3-none-any.whl
Size 9.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0d924cc1cf4fa0c4392824a85f9320279c62ff831cd5fdc66ce0ce33b8588f51
BLAKE2b-256 checksum
How to use checksums
1df702adc7f35cc4119ec3d52ed814d2bcecfd4fa36c1956d5379ffb044957f8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.7.1

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

3 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page