I'm using pytest and have something like the following in conftest.py:
def pytest_addoption(parser):
parser.addoption('--foo', required=True, help='Foo name.')
@pytest.fixture(scope='session')
def foo(pytestconfig):
with Foo(pytestconfig.getoption('foo')) as foo_obj:
yield foo_obj
I'd like to change the --foo option to
parser.addoption('--foo', action='append', help='Foo names.')
and have a separate Foo object with session scope generated for each provided name. Ordinarily, I'd use pytest_generate_tests to parametrize a fixture in this way. That is,
def pytest_generate_tests(metafunc):
if 'foo' in metafunc.fixturenames:
metafunc.parametrize('foo', map(Foo, metafunc.config.getoption('foo')))
However, If I'm understanding correctly how pytest_generate_tests works, Foo objects will be created separately for each test function thus defeating the whole point of a session fixture.