Пример #1
0
        def _scenario(request):
            # Get the feature
            base_path = request.getfuncargvalue('pytestbdd_feature_base_dir')
            feature_path = op.abspath(op.join(base_path, feature_name))
            feature = Feature.get_feature(feature_path)

            # Get the scenario
            try:
                scenario = feature.scenarios[scenario_name]
            except KeyError:
                raise ScenarioNotFound(
                    'Scenario "{0}" in feature "{1}" is not found.'.format(
                        scenario_name, feature_name))

            resolved_params = scenario.params.intersection(
                request.fixturenames)

            if scenario.params != resolved_params:
                raise NotEnoughScenarioParams(
                    """Scenario "{0}" in the feature "{1}" was not able to resolve all declared parameters."""
                    """Should resolve params: {2}, but resolved only: {3}.""".
                    format(scenario_name, feature_name,
                           sorted(scenario.params), sorted(resolved_params)))

            # Execute scenario's steps
            for step in scenario.steps:
                step_func = request.getfuncargvalue(step)
                kwargs = dict((arg, request.getfuncargvalue(arg))
                              for arg in inspect.getargspec(step_func).args)
                step_func(**kwargs)
Пример #2
0
        def _scenario(request):
            # Get the feature
            base_path = request.getfuncargvalue('pytestbdd_feature_base_dir')
            feature_path = op.abspath(op.join(base_path, feature_name))
            feature = Feature.get_feature(feature_path)

            # Get the scenario
            try:
                scenario = feature.scenarios[scenario_name]
            except KeyError:
                raise ScenarioNotFound(
                    'Scenario "{0}" in feature "{1}" is not found.'.format(scenario_name, feature_name))

            resolved_params = scenario.params.intersection(request.fixturenames)

            if scenario.params != resolved_params:
                raise NotEnoughScenarioParams(
                    """Scenario "{0}" in the feature "{1}" was not able to resolve all declared parameters."""
                    """Should resolve params: {2}, but resolved only: {3}.""".format(
                    scenario_name, feature_name, sorted(scenario.params), sorted(resolved_params)))

            # Execute scenario's steps
            for step in scenario.steps:
                step_func = request.getfuncargvalue(step)
                kwargs = dict((arg, request.getfuncargvalue(arg)) for arg in inspect.getargspec(step_func).args)
                step_func(**kwargs)
Пример #3
0
def scenario(
        feature_name, scenario_name, encoding='utf-8', example_converters=None,
        caller_module=None, caller_function=None):
    """Scenario."""

    caller_module = caller_module or get_caller_module()
    caller_function = caller_function or get_caller_function()

    # Get the feature
    base_path = get_fixture(caller_module, 'pytestbdd_feature_base_dir')
    feature_path = op.abspath(op.join(base_path, feature_name))
    feature = Feature.get_feature(feature_path, encoding=encoding)

    # Get the scenario
    try:
        scenario = feature.scenarios[scenario_name]
    except KeyError:
        raise exceptions.ScenarioNotFound(
            'Scenario "{0}" in feature "{1}" is not found.'.format(scenario_name, feature_name)
        )

    scenario.example_converters = example_converters

    # Validate the scenario
    scenario.validate()

    return _get_scenario_decorator(
        feature, feature_name, scenario, scenario_name, caller_module, caller_function, encoding)
Пример #4
0
        def _scenario(request):
            # Get the feature
            base_path = request.getfuncargvalue('pytestbdd_feature_base_dir')
            feature_path = op.abspath(op.join(base_path, feature_name))
            feature = Feature.get_feature(feature_path)

            # Get the scenario
            try:
                scenario = feature.scenarios[scenario_name]
            except KeyError:
                raise ScenarioNotFound(
                    'Scenario "{0}" in feature "{1}" is not found.'.format(scenario_name, feature_name)
                )

            resolved_params = scenario.params.intersection(request.fixturenames)

            if scenario.params != resolved_params:
                raise NotEnoughScenarioParams(
                    """Scenario "{0}" in the feature "{1}" was not able to resolve all declared parameters."""
                    """Should resolve params: {2}, but resolved only: {3}.""".format(
                        scenario_name, feature_name, sorted(scenario.params), sorted(resolved_params),
                    )
                )

            givens = set()
            # Execute scenario steps
            for step in scenario.steps:
                step_func = _find_step_function(request, step.name)

                # Check the step types are called in the correct order
                if step_func.step_type != step.type:
                    raise StepTypeError(
                        'Wrong step type "{0}" while "{1}" is expected.'.format(step_func.step_type, step.type)
                    )

                # Check if the fixture that implements given step has not been yet used by another given step
                if step.type == GIVEN:
                    if step_func.fixture in givens:
                        raise GivenAlreadyUsed(
                            'Fixture "{0}" that implements this "{1}" given step has been already used.'.format(
                                step_func.fixture, step.name,
                            )
                        )
                    givens.add(step_func.fixture)

                # Get the step argument values
                kwargs = dict((arg, request.getfuncargvalue(arg)) for arg in inspect.getargspec(step_func).args)

                # Execute the step
                step_func(**kwargs)
Пример #5
0
        def _scenario(request):
            # Get the feature
            base_path = request.getfuncargvalue('pytestbdd_feature_base_dir')
            feature_path = op.abspath(op.join(base_path, feature_name))
            feature = Feature.get_feature(feature_path)

            # Get the scenario
            try:
                scenario = feature.scenarios[scenario_name]
            except KeyError:
                raise ScenarioNotFound(
                    'Scenario "{0}" in feature "{1}" is not found.'.format(scenario_name, feature_name))

            resolved_params = scenario.params.intersection(request.fixturenames)

            if scenario.params != resolved_params:
                raise NotEnoughScenarioParams(
                    """Scenario "{0}" in the feature "{1}" was not able to resolve all declared parameters."""
                    """Should resolve params: {2}, but resolved only: {3}.""".format(
                    scenario_name, feature_name, sorted(scenario.params), sorted(resolved_params)))

            # Execute scenario's steps
            for step in scenario.steps:
                step_func, kwargs = None, None
            
                try:
                    step_func = request.getfuncargvalue(step)
                    kwargs = dict((arg, request.getfuncargvalue(arg)) for arg in inspect.getargspec(step_func).args)
                    step_func(**kwargs)
                except python.FixtureLookupError:
                    m = None
                    
                    # Find the fixture this step matches
                    fm = request._fixturemanager
                    for name, fixturedef in fm._arg2fixturedefs.items():
                        faclist = list(fm._matchfactories(fixturedef, request._parentid))
                        if faclist:
                            m = re.match(name, step)
                            if m is not None:
                                break
                    
                    step_func = request.getfuncargvalue(m.re.pattern)
                    
                    # Match the function parameters
                    kwargs = m.groupdict()
                    for arg in inspect.getargspec(step_func).args:
                        if arg not in kwargs:
                            kwargs[arg] = request.getfuncargvalue(arg)
                        
                    step_func(**kwargs)
Пример #6
0
    def _scenario(request):
        library = Library(request, module)
        feature = Feature.get_feature(feature_path)
        try:
            scenario = feature.scenarios[scenario_name]
        except KeyError:
            raise ScenarioNotFound('Scenario "{0}" in feature "{1}" is not found'.format(scenario_name, feature_name))

        # Evaluate given steps (can have side effects)
        for given in scenario.given:
            fixture = library.given[given]
            request.getfuncargvalue(fixture)

        # Execute other steps
        for step in scenario.steps:
            _execute_step(request, library.steps[step])
Пример #7
0
    def _scenario(request):
        # Get the feature
        base_path = request.getfuncargvalue('pytestbdd_feature_base_dir')
        feature_path = op.abspath(op.join(base_path, feature_name))
        feature = Feature.get_feature(feature_path)

        # Get the scenario
        try:
            scenario = feature.scenarios[scenario_name]
        except KeyError:
            raise ScenarioNotFound('Scenario "{0}" in feature "{1}" is not found'.format(scenario_name, feature_name))

        # Execute scenario's steps
        for step in scenario.steps:
            func = request.getfuncargvalue(step)
            kwargs = dict((arg, request.getfuncargvalue(arg)) for arg in inspect.getargspec(func).args)
            func(**kwargs)