Skip to main content

A module for generating tests from data with unittest

Project description

A module for generating tests from data with unittest

Installation:

Install using pip:

pip install gentests

Example:

The following test code will generate 10 tests:

import unittest
from gentests import gentests, vals

def my_less_than(a,b):
    '''Broken function to test'''
    return a <= b

@gentests
class TestSomething(unittest.TestCase):


    @vals([
        'val_0',
        'val_1',
        'val_2'
    ])
    def test_False(self, value):
        '''Test that fails'''
        self.assertFalse(True)

    @vals([
        'val_0',
        'val_1',
        'val_2'
    ])
    def test_True(self, value):
        '''Test that passes'''
        self.assertTrue(True)

    def name_test(original_name, left, right, result):
        '''Explicitly name our tests based on our arguments'''
        return '{0}_my_less_than_{1}_{2}_is_{3}'.format(
            original_name,
            str(left),
            str(right),
            str(result)
        )

    @vals([
        (0, 1, True),
        (0, 0, False), #Fails
        (0, 2, True),
        (2, 1, False),
    ], name=name_test) #pass optional naming function
    def test_MyLessThan(self, left, right, result):
        '''Test where some pass and some fail'''
        self.assertEqual(my_less_than(left, right), result)

if __name__ == '__main__':
    unittest.main()

that produce the following output:

FFFF......
======================================================================
FAIL: test_False_gentest_0 (test.TestSomething)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\Users\Redirection\windoj9\Documents\repos\GenTests\gentests.py", line 17, in <lambda>
    return lambda other_self: base_func(other_self, *args)
  File "C:\Users\Redirection\windoj9\Documents\repos\GenTests\test.py", line 19, in test_False
    self.assertFalse(True)
AssertionError: True is not false

======================================================================
FAIL: test_False_gentest_1 (test.TestSomething)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\Users\Redirection\windoj9\Documents\repos\GenTests\gentests.py", line 17, in <lambda>
    return lambda other_self: base_func(other_self, *args)
  File "C:\Users\Redirection\windoj9\Documents\repos\GenTests\test.py", line 19, in test_False
    self.assertFalse(True)
AssertionError: True is not false

======================================================================
FAIL: test_False_gentest_2 (test.TestSomething)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\Users\Redirection\windoj9\Documents\repos\GenTests\gentests.py", line 17, in <lambda>
    return lambda other_self: base_func(other_self, *args)
  File "C:\Users\Redirection\windoj9\Documents\repos\GenTests\test.py", line 19, in test_False
    self.assertFalse(True)
AssertionError: True is not false

======================================================================
FAIL: test_MyLessThan_my_less_than_0_0_is_False (test.TestSomething)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\Users\Redirection\windoj9\Documents\repos\GenTests\gentests.py", line 17, in <lambda>
    return lambda other_self: base_func(other_self, *args)
  File "C:\Users\Redirection\windoj9\Documents\repos\GenTests\test.py", line 47, in test_MyLessThan
    self.assertEqual(my_less_than(left, right), result)
AssertionError: True != False

----------------------------------------------------------------------
Ran 10 tests in 0.006s

FAILED (failures=4)

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

gentests-1.0.0.zip (4.0 kB view details)

Uploaded Source

Built Distribution

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

gentests-1.0.0-py3-none-any.whl (2.8 kB view details)

Uploaded Python 3

File details

Details for the file gentests-1.0.0.zip.

File metadata

  • Download URL: gentests-1.0.0.zip
  • Upload date:
  • Size: 4.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for gentests-1.0.0.zip
Algorithm Hash digest
SHA256 88100d83754aa33c9c1f27906e3c41ee859c93c0f31810f9985f2f923442db3a
MD5 90808d197c253bde586cb76c78cdface
BLAKE2b-256 3c51c683e6e497838b5b2e9526b1bd071148d34bdd212b315f2029d35762a1af

See more details on using hashes here.

File details

Details for the file gentests-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for gentests-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 73a1f594b398d184b4cc078109ae32d495e1635e844275e4cd6e54a86f46c126
MD5 7ff1361a419220db670f47436f612135
BLAKE2b-256 5a2727af3b549c19e8b01c856003661e68bdb03e95415fc5f4850529d1eac534

See more details on using hashes here.

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