Exemplo n.º 1
0
 def _setup_fixtures(self, scope=None):
     if scope is None:
         scope = self.fixture_scope
     # Ensure scoped fixtures are run in the correct behave context
     with self.runner.context.user_mode():
         for fixturename in self.fixturenames:
             if fixturename == 'request':
                 continue
             fixture_scope = self._fixtureinfo.name2fixturedefs[fixturename][-1].scope
             if scopemismatch(scope, fixture_scope):
                 continue
             self._request.getfuncargvalue(fixturename)
Exemplo n.º 2
0
 def _setup_fixtures(self, scope=None):
     if scope is None:
         scope = self.fixture_scope
     # Ensure scoped fixtures are run in the correct behave context
     with self.runner.context.user_mode():
         for fixturename in self.fixturenames:
             if fixturename == 'request':
                 continue
             fixture_scope = self._fixtureinfo.name2fixturedefs[
                 fixturename][-1].scope
             if scopemismatch(scope, fixture_scope):
                 continue
             self._request.getfuncargvalue(fixturename)
Exemplo n.º 3
0
    def _getfuncargvalue(self, fixturedef):
        # prepare a subrequest object before calling fixture function
        # (latter managed by fixturedef)
        argname = fixturedef.argname
        funcitem = self._pyfuncitem
        scope = fixturedef.scope
        try:
            param = funcitem.callspec.getparam(argname)
        except (AttributeError, ValueError):
            param = NOTSET
            param_index = 0
        else:
            # indices might not be set if old-style metafunc.addcall() was used
            param_index = funcitem.callspec.indices.get(argname, 0)
            # if a parametrize invocation set a scope it will override
            # the static scope defined with the fixture function
            paramscopenum = funcitem.callspec._arg2scopenum.get(argname)
            if paramscopenum is not None:
                scope = scopes[paramscopenum]

        subrequest = BDDSubRequest(self, scope, param, param_index, fixturedef)

        # check if a higher-level scoped fixture accesses a lower level one
        if scope is not None:
            __tracebackhide__ = True
            if scopemismatch(self.scope, scope):
                # try to report something helpful
                lines = subrequest._factorytraceback()
                raise ScopeMismatchError(
                    "You tried to access the %r scoped "
                    "fixture %r with a %r scoped request object, "
                    "involved factories\n%s" %
                    ((scope, argname, self.scope, "\n".join(lines))))
            __tracebackhide__ = False

        try:
            # call the fixture function
            val = fixturedef.execute(request=subrequest)
        finally:
            # if fixture function failed it might have registered finalizers
            self.session._setupstate.addfinalizer(fixturedef.finish,
                                                  subrequest.node)
        return val
Exemplo n.º 4
0
    def _getfuncargvalue(self, fixturedef):
        # prepare a subrequest object before calling fixture function
        # (latter managed by fixturedef)
        argname = fixturedef.argname
        funcitem = self._pyfuncitem
        scope = fixturedef.scope
        try:
            param = funcitem.callspec.getparam(argname)
        except (AttributeError, ValueError):
            param = NOTSET
            param_index = 0
        else:
            # indices might not be set if old-style metafunc.addcall() was used
            param_index = funcitem.callspec.indices.get(argname, 0)
            # if a parametrize invocation set a scope it will override
            # the static scope defined with the fixture function
            paramscopenum = funcitem.callspec._arg2scopenum.get(argname)
            if paramscopenum is not None:
                scope = scopes[paramscopenum]

        subrequest = BDDSubRequest(self, scope, param, param_index, fixturedef)

        # check if a higher-level scoped fixture accesses a lower level one
        if scope is not None:
            __tracebackhide__ = True
            if scopemismatch(self.scope, scope):
                # try to report something helpful
                lines = subrequest._factorytraceback()
                raise ScopeMismatchError("You tried to access the %r scoped "
                    "fixture %r with a %r scoped request object, "
                    "involved factories\n%s" %(
                    (scope, argname, self.scope, "\n".join(lines))))
            __tracebackhide__ = False

        try:
            # call the fixture function
            val = fixturedef.execute(request=subrequest)
        finally:
            # if fixture function failed it might have registered finalizers
            self.session._setupstate.addfinalizer(fixturedef.finish,
                                                  subrequest.node)
        return val