.fixture.create() in conftest.py breaks when using multiple packages

Issue #9 new
Michael Howitz created an issue

Since #7 .fixture.create() can be called in conftest.py to get fixture names which can be reused in test functions.

This does not work of one of the base layers of the requested layer is used in another package, too because then the fixture function of the base layer is not found there. (Technical detail: the baseid of the fixture function does not match with the nodeid of the function under test. If the fixture function is not created using an explicit call to .fixture.create() the baseid is '' which matches.)

Possible solution:

def {name}({base}):
    return locals()['{base}']

def create_fixture(name, layer, scope='function'):
    """Create a ficxture for a layer."""
    base = gocept.pytestlayer.fixture.get_fixture_name(layer, scope)
    code = FIXTURE_CODE_TEMPLATE.format(**locals())
    ns = {}
    exec(code, {'pytest': pytest}, ns)
    return ns

Example call:

globals().update(create_fixture('internet', INTERNET_SITE_LAYER))


  • discuss possible solution
  • write a test
  • Write down warning about this approach: If a layer is not used on a test case it will not be found. Maybe .fixture.create() can be adapted so that my new function is not necessary.

Comments (1)

  1. Log in to comment