New issue 652: Specify fixture parameter values in parameterize decorator
https://bitbucket.org/hpk42/pytest/issue/652/specify-fixture-parameter-values-in

Olga Botvinnik:

I'm running py.test 2.6.4 and would like to run all parameterizations of a 
fixture in some tests, but not in others, as described in 
[this](http://stackoverflow.com/questions/27735413/use-only-certain-fixture-parameterizations-in-different-tests-in-pytest)
 StackOverflow question. In the MVC-like structure I have, the Model is 
extensively tested with all parameterizations, but the Controller doesn't need 
all parameterizations, and some of them are redundant at that level, so I'd 
like to minimize the number of tests.

Essentially, I have a fixture called `n_groups` which parameterizes to `2` and 
`3`, and then I build several levels of fixtures on top of it to finally create 
a `metadata_data` fixture:

```
#!python
# Contents of conftest.py

@pytest.fixture(scope='module', params=[2, ids=['2_groups', '3_groups'])
def n_groups(request):
    """Number of phenotype groups.

    For testing that functions work when there's only 2 groups
    """
    return request.param

@pytest.fixture(scope='module')
def groups(n_groups):
    """Phenotype group names"""
    return ['group{}'.format(i + 1) for i in np.arange(n_groups)]

@pytest.fixture(scope='module')
def groupby(groups, samples):
    return dict((sample, np.random.choice(groups)) for sample in samples)

@pytest.fixture(scope='module')
def metadata_data(groupby, outliers, pooled, samples,
                  n_samples,
                  metadata_phenotype_col):
    df = pd.DataFrame(index=samples)
    if outliers is not None:
        df['outlier'] = df.index.isin(outliers)
    if pooled is not None:
        df['pooled'] = df.index.isin(pooled)
    df[metadata_phenotype_col] = groupby
    df['subset1'] = np.random.choice([True, False], size=n_samples)
    return df
```

What I would like to be able to do is, for certain tests, specify the 
`n_groups` parameterization through either the value or the ID, like this:

```
#!python
# Contents of test_model.py
class TestModel(object):
    def test__init(metadata_data, ...):
        ...

    @pytest.mark.parameterize(n_groups=3)
    def test_plot(metadata_data, ...);
        ...
```

```
#!python
# Contents of test_controller.py
class TestController(object):
    @pytest.mark.parameterize(n_groups=3)
    def test__init(metadata_data, ...):
        ...
```

It seems this is not possible given the current structure of `pytest`. Are 
there plans to add such a feature in the future?

Thank you for creating this excellent package! It has been really great to 
generate tons of test when just writing one function.


_______________________________________________
pytest-commit mailing list
pytest-commit@python.org
https://mail.python.org/mailman/listinfo/pytest-commit

Reply via email to