File: issue0077.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 (89 lines) | stat: -rw-r--r-- 2,829 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
@issue
Feature: Issue #77: Does not capture stdout from sub-processes

  . My step functions are using wrapper objects to interact with SUT.
  . Those wrappers use this kind of thing to invoke executables:
  .
  .   subprocess.check_call('myprog', ..., stderr=subprocess.STDOUT)
  .
  . However, the output from those calls does not appear in the stdout
  . captured by behave when a step fails.


  Background: Test Setup
    Given a new working directory
    Given a file named "hello.py" with:
        """
        import sys

        def hello():
            result = 0
            args = sys.argv[1:]
            if args and args[0].startswith("--fail"):
                result = 1
                args   = args[1:]
            message = " ".join(args)
            sys.stdout.write("Hello {0}\n".format(message))
            sys.exit(result)

        if __name__ == "__main__":
            hello()
        """
    And   a file named "features/steps/subprocess_call_steps.py" with:
        """
        from behave import given, when, then
        import subprocess
        import os.path
        import sys

        PYTHON = sys.executable
        HERE = os.path.dirname(__file__)

        @when(u'I make a subprocess call "hello {commandline}"')
        def step(context, commandline):
            result = subprocess_call_hello(commandline.split())
            assert result == 0

        def subprocess_call_hello(args):
            command_args = [ PYTHON, "hello.py" ] + args
            result = subprocess.check_call(command_args, stderr=subprocess.STDOUT)
            return result
            # result = subprocess.check_output(command_args, stderr=subprocess.STDOUT)
            # return result
        """

  Scenario: Subprocess call shows generated output
    Given a file named "features/issue77_hello_OK.feature" with:
        """
        Feature:
          Scenario:
            When I make a subprocess call "hello world."
        """
    When I run "behave -f plain features/issue77_hello_OK.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:
        """
        Hello world.
        """

  Scenario: Subprocess call fails with captured output
    Given a file named "features/issue77_hello_FAIL.feature" with:
        """
        Feature:
          Scenario:
            When I make a subprocess call "hello --fail FAIL."
        """
    When I run "behave -f plain features/issue77_hello_FAIL.feature"
    Then it should fail with:
        """
        0 scenarios passed, 1 failed, 0 skipped
        0 steps passed, 1 failed, 0 skipped, 0 undefined
        """
    And the command output should contain:
        """
        Hello FAIL.
        """