Giter Site home page Giter Site logo

python-string-test-runner's Introduction

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

python-string-test-runner's People

Contributors

toshikurauchi avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

Forkers

gabriellaec

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.