Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a list of twelve properties and want to test various combinations. The actual test function is the same, just different parameters. I find myself writing a bunch of functions that look like this:

def test_paramA(self): self.with_params("A")
def test_paramA_B(self): self.with_params("A+B")
def test_paramA_C(self): self.with_params("A+C")
def test_paramB_C(self): self.with_params("B+C")

I'd like to instead write this:

combinations = ["A", "A+B", "A+C", "B+C"]
combinationSuite = (make_test_function(c) for c in combinations)

Is there any way to make my test driver (nosetests) run all the tests in combinationSuite? Do I need a custom test collector?

share|improve this question
up vote 3 down vote accepted

Nose supports parametric/generative tests,

For example:

def checker(combination):
    # do something to verify the combination 
    assert 'A' in combination

def test_generator():
    options = ['A', 'B', 'C']
    for o in options:
        yield checker, o

    for p in itertools.permutations(options, 2):
        yield checker, p

9 tests are created by nose and results in 4 failures, which would be expected. Also, beware that generative tests do not work with unittest.TestCase subclasses.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.