How to use step_then_feature_files_are_selected_with_text method in Behave

Best Python code snippet using behave

Run Behave automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

behave_select_files_steps.py

Source: behave_select_files_steps.py Github

copy
1# -*- coding: utf-8 -*-
2"""
3Provides step definitions that test how the behave runner selects feature files.
4
5EXAMPLE:
6    Given behave has the following feature fileset:
7      '''
8      features/alice.feature
9      features/bob.feature
10      features/barbi.feature
11      '''
12    When behave includes feature files with "features/a.*\.feature"
13    And  behave excludes feature files with "features/b.*\.feature"
14    Then the following feature files are selected:
15      '''
16      features/alice.feature
17      '''
18"""
19
20from __future__ import absolute_import
21from behave import given, when, then
22from behave.runner_util import FeatureListParser
23from hamcrest import assert_that, equal_to
24from copy import copy
25import re
26import six
27
28# -----------------------------------------------------------------------------
29# STEP UTILS:
30# -----------------------------------------------------------------------------
31class BasicBehaveRunner(object):
32    def __init__(self, config=None):
33        self.config = config
34        self.feature_files = []
35
36    def select_files(self):
37        """
38        Emulate behave runners file selection by using include/exclude patterns.
39        :return: List of selected feature filenames.
40        """
41        selected = []
42        for filename in self.feature_files:
43            if not self.config.exclude(filename):
44                selected.append(six.text_type(filename))
45        return selected
46
47# -----------------------------------------------------------------------------
48# STEP DEFINITIONS:
49# -----------------------------------------------------------------------------
50@given('behave has the following feature fileset')
51def step_given_behave_has_feature_fileset(context):
52    assert context.text is not None, "REQUIRE: text"
53    behave_runner = BasicBehaveRunner(config=copy(context.config))
54    behave_runner.feature_files = FeatureListParser.parse(context.text)
55    context.behave_runner = behave_runner
56
57@when('behave includes all feature files')
58def step_when_behave_includes_all_feature_files(context):
59    assert context.behave_runner, "REQUIRE: context.behave_runner"
60    context.behave_runner.config.include_re = None
61
62@when('behave includes feature files with "{pattern}"')
63def step_when_behave_includes_feature_files_with_pattern(context, pattern):
64    assert context.behave_runner, "REQUIRE: context.behave_runner"
65    context.behave_runner.config.include_re = re.compile(pattern)
66
67@when('behave excludes no feature files')
68def step_when_behave_excludes_no_feature_files(context):
69    assert context.behave_runner, "REQUIRE: context.behave_runner"
70    context.behave_runner.config.exclude_re = None
71
72@when('behave excludes feature files with "{pattern}"')
73def step_when_behave_excludes_feature_files_with_pattern(context, pattern):
74    assert context.behave_runner, "REQUIRE: context.behave_runner"
75    context.behave_runner.config.exclude_re = re.compile(pattern)
76
77@then('the following feature files are selected')
78def step_then_feature_files_are_selected_with_text(context):
79    assert context.text is not None, "REQUIRE: text"
80    assert context.behave_runner, "REQUIRE: context.behave_runner"
81    selected_files = context.text.strip().splitlines()
82    actual_files = context.behave_runner.select_files()
83    assert_that(actual_files, equal_to(selected_files))
84
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Run Python Tests on LambdaTest Cloud Grid

Execute automation tests with Behave on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)