py.test run tests in specific testSuite
Question: I'm new to py.test. So far I like what I see and want to integrate it to our
CI process.

Currently we use a different kind of parameterization scheme for our tests
which I will explain briefly:

  * instead of parameterizing per-test, we parameterize per class
  * say `params` is a touple of of of tuples, each representing different set of parameters.
  * we create for each such tupla different instance of some `TestCaseWithParameters` which is a `unittest.TestCase` class. Something like this:

>
>         for test_parameters in params:
>
> parameterized_test_suite.addTest(ParametrizedTestCase.parametrize(TestCaseWithParameters,param=test_parameters))
>  

  * Each of these classes is injected with `self.params` and runs all tests functions it with those different params.
  * This means that if we have hundreds of tuples in `params` and `TestSomethingWithParameters` has dozens of tests, there are _a lot_ of tests in total.

My question: How would I go about translating this to py.test?

I've read [this](http://holgerkrekel.net/2009/05/13/parametrizing-python-
tests-generalized/) article about the `pytest_generate_tests` hook, but it
seems it injects dependency per test function, and I need it per TestCase...

The simplest way would be to tell py.test to run the specific
`parameterized_tes_suite` I create already, but I did not find a way to do
so...

A different way would be to do a similar dependency-injection at TestCase
class level, but I have not found a way to do that either.


Answer: You can easily parametrize whole classes using the `@pytest.mark.parametrize`
marker:

    
    
    import pytest
    
    @pytest.mark.parametrize('n', [0, 1])
    class TestFoo:
    
        def test_42(self, n):
            assert n == 42
    
        def test_7(self, n):
            assert n == 7
    

See the [documentation on the parameterize
marker](http://pytest.org/latest/parametrize.html#pytest-mark-parametrize-
parametrizing-test-functions) for details on how to pass in multiple arguments
etc. And also have a look at how to [apply markers to classes and
modules](http://pytest.org/latest/example/markers.html#marking-whole-classes-
or-modules) for more information on this.

