Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
sallner opened this issue Nov 25, 2019 · 0 comments
Open
Labels
enhancement New feature or request

Comments

@sallner
Copy link
Member

sallner commented Nov 25, 2019

transferred from bitbucket:

Michael Howitz created an issue 2016-08-16

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:

FIXTURE_CODE_TEMPLATE = """
@pytest.fixture('{scope}')
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))

Tasks:

  • 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.
@sallner sallner added the enhancement New feature or request label Nov 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant