Debian Codegraph @

features/feature.exclude_from_run.feature

raw
1 Feature: Exclude Feature from Test Run
2
3 As a test writer
4 I want sometimes to decide at runtime
5 that a feature is excluded from a test run
6 So that the command-line configuration becomes simpler
7 (and auto-configuration is supported).
8
9 . MECHANISM:
10 . The "before_feature()" hook can decide just before a feature should run
11 . that the feature should be excluded from the test-run.
12 . NOTE: Hooks are not called in dry-run mode.
13 .
14 . RATIONALE:
15 . There are certain situations where it is better to skip a feature
16 . than to run and fail the feature.
17 .
18 . Reasons for these cases are of often test environment related:
19 . * test environment does not fulfill the desired criteria
20 . * used testbed does not fulfill test requirements
21 .
22 . Instead of providing the exclude-feature selection on the command-line,
23 . the test (environment) and configuration logic should determine
24 . if a test should be excluded (as auto-configuration functionality).
25 .
26 . EXAMPLE:
27 . Certain features should not run on Windows (or Linux, ...).
28 .
29 . EVALUATION ORDER:
30 . Before the user can exclude a feature from a test-run,
31 . additional mechanisms decide, if the feature is part of the selected run-set.
32 . These are:
33 . * tags
34 . * ...
35 .
36 . RELATED:
37 . * features/scenario.exclude_from_run.feature
38
39
40 @setup
41 Scenario:
42 Given a new working directory
43 And a file named "features/alice.feature" with:
44 """
45 Feature: Alice
46 Scenario: Alice in Wonderland
47 Given a step passes
48 When another step passes
49 Then some step passes
50
51 Scenario: Alice and Bob
52 Given another step passes
53 """
54 And a file named "features/bob.feature" with:
55 """
56 Feature: Bob
57 Scenario: Bob in Berlin
58 Given some step passes
59 When another step passes
60 """
61 And a file named "features/steps/steps.py" with:
62 """
63 from behave import step
64
65 @step('{word:w} step passes')
66 def step_passes(context, word):
67 pass
68 """
69
70
71 Scenario: Exclude a feature from the test run (using: before_feature() hook)
72 Given a file named "features/environment.py" with:
73 """
74 import sys
75
76 def should_exclude_feature(feature):
77 if "Alice" in feature.name:
78 return True
79 return False
80
81 def before_feature(context, feature):
82 if should_exclude_feature(feature):
83 sys.stdout.write("EXCLUDED-BY-USER: Feature %s\n" % feature.name)
84 feature.skip()
85 """
86 When I run "behave -f plain -T features/"
87 Then it should pass with:
88 """
89 1 feature passed, 0 failed, 1 skipped
90 1 scenario passed, 0 failed, 2 skipped
91 2 steps passed, 0 failed, 4 skipped, 0 undefined
92 """
93 And the command output should contain:
94 """
95 EXCLUDED-BY-USER: Feature Alice
96 """