Skip to main content

Runs test code contained in strings

Project description

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

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

strtest-0.1.0.tar.gz (7.9 kB view hashes)

Uploaded Source

Built Distribution

strtest-0.1.0-py3-none-any.whl (9.4 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page