Skip to main content

Nose decorator for parameterized testing

Project description

Nose. It’s got test generators. But they kind of suck, because:

  • They often require a second function

  • They make it difficult to separate the data from the test

  • They don’t work with subclases of unittest.TestCase

But nose-parameterized fixes that:

$ cat test_math.py
from nose.tools import assert_equal
from nose_parameterized import parameterized

import unittest
import math

@parameterized([
    (2, 2, 4),
    (2, 3, 8),
    (1, 9, 1),
    (0, 9, 0),
])
def test_pow(base, exponent, expected):
    assert_equal(math.pow(base, exponent), expected)


class TestMathUnitTest(unittest.TestCase):
    @parameterized.expand([
        (-1.5, -2.0),
        (1.0, 1.0),
        (1.6, 1),
    ])
    def test_floor(self, input, expected):
        assert_equal(math.floor(input), expected)
$ nosetests -v test_math.py
test_math.test_pow(2, 2, 4) ... ok
test_math.test_pow(2, 3, 8) ... ok
test_math.test_pow(1, 9, 1) ... ok
test_math.test_pow(0, 9, 0) ... ok
test_floor_0 (test_math.TestMathUnitTest) ... ok
test_floor_1 (test_math.TestMathUnitTest) ... ok
test_floor_2 (test_math.TestMathUnitTest) ... ok

----------------------------------------------------------------------
Ran 7 tests in 0.002s

OK

Now with Python 3 support!

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

nose-parameterized-0.2.tar.gz (8.0 kB view details)

Uploaded Source

File details

Details for the file nose-parameterized-0.2.tar.gz.

File metadata

File hashes

Hashes for nose-parameterized-0.2.tar.gz
Algorithm Hash digest
SHA256 038e323562ef5995d0dda6a6382ed8f5ddb4ca0b3974efc73e52afa4e2fe1813
MD5 b626751beec646cfa912ee5cfe1e43ee
BLAKE2b-256 81ae495a05b1fe50680699ef95df486c050bdb687c70679d9190ca48507f3d6a

See more details on using hashes here.

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