jeudi 24 septembre 2015

pytest: How to pass in values and create a test fixture from command line?

I have a simple test as shown below:

# contents of test_example
def test_addition(numbers):

    assert numbers < 5

And below is my conftest

# contents of conftest
import pytest

@pytest.fixture(params=[1, 2, 3, 4])
def numbers(request):
    return request.param

However now I want to test the numbers 5 and 6but not have to explicitly hardcode that. On command line, I would like to override the numbers test fixture with the numbers 5 and 6 such that:

py.test test_example.py --numbers=[5, 6]

I would expect the result of the above invocation to overwrite the conftest numbers test fixture with my test fixture created at command line and run test_addition() on 5 and 6 only.

How would I go about doing this?

Aucun commentaire:

Enregistrer un commentaire