File: step.import_other_step_module.feature

package info (click to toggle)
behave 1.2.6-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,160 kB
  • sloc: python: 19,857; makefile: 137; sh: 18
file content (103 lines) | stat: -rw-r--r-- 3,204 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
Feature: Ensure that a step module can import another step module

  As a test writer
  I want to import step definitions from another module in a step module
  So that I can reuse other steps and call them directly.

  . When a step module imports another step module
  . this should not cause AmbiguousStep errors
  . due to duplicated registration of the same step functions.
  .
  . NOTES:
  .   * In general you should avoid this case (provided as example here).
  .   * Use "context.execute_steps(...)" to avoid importing other step modules
  .   * Use step-libraries; this will in general use sane imports of other step modules


  Scenario: Step module that imports another step module
    Given a new working directory
    And a file named "features/steps/alice1_steps.py" with:
      """
      from behave import given

      @given(u'I call Alice')
      def step_call_alice(context):
          pass
      """
    And   a file named "features/steps/bob1_steps.py" with:
      """
      from behave import given
      from alice1_steps import step_call_alice

      @given(u'I call Bob')
      def step_call_bob(context):
          pass

      @given(u'I call Bob and Alice')
      def step_call_bob_and_alice(context):
          step_call_bob(context)
          step_call_alice(context)
      """
    And a file named "features/example.import_step_module.feature" with:
      """
      Feature:
        Scenario:
          Given I call Bob and Alice
      """
    When I run "behave -f plain --no-timings features/example.import_step_module.feature"
    Then it should pass with:
        """
        1 scenario passed, 0 failed, 0 skipped
        1 step passed, 0 failed, 0 skipped, 0 undefined
        """
    And the command output should contain:
        """
        Feature:
            Scenario:
              Given I call Bob and Alice ... passed
        """


  Scenario: Step module that imports another step module (cross-wise)
    Given a new working directory
    And a file named "features/steps/alice2_steps.py" with:
      """
      from behave import given
      import bob2_steps     # -- BAD: Import other step module, cross-wise.

      @given(u'I call Alice')
      def step_call_alice(context):
          pass
      """
    And   a file named "features/steps/bob2_steps.py" with:
      """
      from behave import given
      import alice2_steps     # -- BAD: Import other step module, cross-wise.

      @given(u'I call Bob')
      def step_call_bob(context):
          pass
      """
    And a file named "features/example.cross_imported_step_modules.feature" with:
      """
      Feature:
        Scenario:
          Given I call Alice
          And   I call Bob
      """
    When I run "behave -f plain --no-timings features/example.cross_imported_step_modules.feature"
    Then it should pass with:
        """
        1 feature passed, 0 failed, 0 skipped
        1 scenario passed, 0 failed, 0 skipped
        2 steps passed, 0 failed, 0 skipped, 0 undefined
        """
    And the command output should contain:
        """
        Feature:
            Scenario:
              Given I call Alice ... passed
              And I call Bob ... passed
        """