Ejemplo n.º 1
0
def pytest_generate_tests(metafunc):
    from cfme.markers.env_markers.provider import ProviderEnvironmentMarker
    markers = [
        BrowserEnvironmentMarker(),
        TCPEnvironmentMarker(),
        ProviderEnvironmentMarker()
    ]
    for marker in markers:
        marker.process_env_mark(metafunc)
Ejemplo n.º 2
0
def pytest_fixture_setup(fixturedef, request):
    # since we use DataProvider at collection time and BaseProvider in fixtures and tests,
    # we need to instantiate BaseProvider and replace DataProvider obj with it right before first
    # provider fixture request.
    # There were several other ways to do that. However, those bumped into different
    # scope mismatch issues.

    # As the object may not be the root object and may have a parent, we need to walk to that
    # the object to see if we can find the attribute on it or any of its parents
    parent = _walk_to_obj_parent(request)
    # node has all the markers from full scope
    # default it to empty dict so loop below shorts and yields at the end
    item_marks = ProviderEnvironmentMarker.get_closest_kwarg_markers(parent.node) or {}

    for fixture_name, mark in item_marks.items():
        if fixture_name == fixturedef.argname:
            kwargs = {}
            for argname in fixturedef.argnames:
                fixdef = request._get_active_fixturedef(argname)
                result, arg_cache_key, exc = fixdef.cached_result
                request._check_scope(argname, request.scope, fixdef.scope)
                kwargs[argname] = result

            fixturefunc = fixturedef.func
            if request.instance is not None:
                fixturefunc = getimfunc(fixturedef.func)
                if fixturefunc != fixturedef.func:
                    fixturefunc = fixturefunc.__get__(request.instance)
            # Use the DataProvider instance as the cache key.
            my_cache_key = request.param
            try:
                provider_data = call_fixture_func(fixturefunc, request, kwargs)
            except TEST_OUTCOME:
                fixturedef.cached_result = (None, my_cache_key, sys.exc_info())
                raise
            from cfme.utils.providers import get_crud
            provider = get_crud(provider_data.key)
            request.param = provider
            yield provider
            # Store the cached_result after we have yielded to other pytest_fixture_setup methods.
            fixturedef.cached_result = (provider, my_cache_key, None)
            break
    else:
        yield
Ejemplo n.º 3
0
def pytest_fixture_setup(fixturedef, request):
    """Use DataProvider instances at collection time, and BaseProvider subclass instances in
    fixture / test execution. This method instantiates the BaseProvider object from the provider
    information stored in the DataProvider instance."""

    # As the object may have a parent, walk to that object to see if we can find the attribute.
    parent = _walk_to_obj_parent(request)

    # parent.node has all the markers from the full scope.
    item_marks = ProviderEnvironmentMarker.get_closest_kwarg_markers(
        parent.node) or {}

    for fixture_name in item_marks:
        if fixture_name == fixturedef.argname:
            kwargs = {}
            for argname in fixturedef.argnames:
                fixdef = request._get_active_fixturedef(argname)
                assert fixdef.cached_result is not None
                result, arg_cache_key, exc = fixdef.cached_result
                request._check_scope(argname, request.scope, fixdef.scope)
                kwargs[argname] = result

            fixturefunc = resolve_fixture_function(fixturedef, request)
            # Use the DataProvider instance as the cache key.
            my_cache_key = fixturedef.cache_key(request)
            try:
                provider_data = call_fixture_func(fixturefunc, request, kwargs)
            except TEST_OUTCOME:
                fixturedef.cached_result = (None, my_cache_key, sys.exc_info())
                raise

            # Instantiate BaseProvider subclass here, and store as the fixture result.
            from cfme.utils.providers import get_crud
            result = get_crud(provider_data.key)
            request.param = result

            yield result
            # Store the cached_result after we have yielded to other pytest_fixture_setup methods.
            fixturedef.cached_result = (result, my_cache_key, None)
            break
    else:
        yield