Debian Codegraph @

features/step.import_other_step_module.feature

raw
1 Feature: Ensure that a step module can import another step module
2
3 As a test writer
4 I want to import step definitions from another module in a step module
5 So that I can reuse other steps and call them directly.
6
7 . When a step module imports another step module
8 . this should not cause AmbiguousStep errors
9 . due to duplicated registration of the same step functions.
10 .
11 . NOTES:
12 . * In general you should avoid this case (provided as example here).
13 . * Use "context.execute_steps(...)" to avoid importing other step modules
14 . * Use step-libraries; this will in general use sane imports of other step modules
15
16
17 Scenario: Step module that imports another step module
18 Given a new working directory
19 And a file named "features/steps/alice1_steps.py" with:
20 """
21 from behave import given
22
23 @given(u'I call Alice')
24 def step_call_alice(context):
25 pass
26 """
27 And a file named "features/steps/bob1_steps.py" with:
28 """
29 from behave import given
30 from alice1_steps import step_call_alice
31
32 @given(u'I call Bob')
33 def step_call_bob(context):
34 pass
35
36 @given(u'I call Bob and Alice')
37 def step_call_bob_and_alice(context):
38 step_call_bob(context)
39 step_call_alice(context)
40 """
41 And a file named "features/example.import_step_module.feature" with:
42 """
43 Feature:
44 Scenario:
45 Given I call Bob and Alice
46 """
47 When I run "behave -f plain --no-timings features/example.import_step_module.feature"
48 Then it should pass with:
49 """
50 1 scenario passed, 0 failed, 0 skipped
51 1 step passed, 0 failed, 0 skipped, 0 undefined
52 """
53 And the command output should contain:
54 """
55 Feature:
56 Scenario:
57 Given I call Bob and Alice ... passed
58 """
59
60
61 Scenario: Step module that imports another step module (cross-wise)
62 Given a new working directory
63 And a file named "features/steps/alice2_steps.py" with:
64 """
65 from behave import given
66 import bob2_steps # -- BAD: Import other step module, cross-wise.
67
68 @given(u'I call Alice')
69 def step_call_alice(context):
70 pass
71 """
72 And a file named "features/steps/bob2_steps.py" with:
73 """
74 from behave import given
75 import alice2_steps # -- BAD: Import other step module, cross-wise.
76
77 @given(u'I call Bob')
78 def step_call_bob(context):
79 pass
80 """
81 And a file named "features/example.cross_imported_step_modules.feature" with:
82 """
83 Feature:
84 Scenario:
85 Given I call Alice
86 And I call Bob
87 """
88 When I run "behave -f plain --no-timings features/example.cross_imported_step_modules.feature"
89 Then it should pass with:
90 """
91 1 feature passed, 0 failed, 0 skipped
92 1 scenario passed, 0 failed, 0 skipped
93 2 steps passed, 0 failed, 0 skipped, 0 undefined
94 """
95 And the command output should contain:
96 """
97 Feature:
98 Scenario:
99 Given I call Alice ... passed
100 And I call Bob ... passed
101 """
102
103