-
Notifications
You must be signed in to change notification settings - Fork 639
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support scenario hook-errors with JUnitReporter (related to: #466)
FIXES #466
- Loading branch information
Showing
7 changed files
with
184 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
@issue | ||
@junit | ||
Feature: Issue #446 -- Support scenario hook-errors with JUnitReporter | ||
|
||
. Currently, when a hook error occurs in: | ||
. | ||
. * before_scenario() | ||
. * after_scenario() | ||
. | ||
. a sanity check in the JUnitReporter prevents sane JUnit XML output. | ||
|
||
@setup | ||
Scenario: Skip scenario without steps | ||
Given a new working directory | ||
And a file named "features/steps/pass_steps.py" with: | ||
""" | ||
from behave import step | ||
@step('{word:w} step passes') | ||
def step_passes(context, word): | ||
pass | ||
""" | ||
And a file named "features/before_scenario_failure.feature" with: | ||
""" | ||
Feature: Alice | ||
@hook_failure.before_scenario | ||
Scenario: A1 | ||
Given a step passes | ||
""" | ||
And a file named "features/after_scenario_failure.feature" with: | ||
""" | ||
Feature: Bob | ||
@hook_failure.after_scenario | ||
Scenario: B1 | ||
Given another step passes | ||
""" | ||
And a file named "features/environment.py" with: | ||
""" | ||
def cause_hook_failure(): | ||
1 / 0 # CAUSE: ZeroDivisionError | ||
def before_scenario(context, scenario): | ||
if "hook_failure.before_scenario" in scenario.tags: | ||
cause_hook_failure() | ||
def after_scenario(context, scenario): | ||
if "hook_failure.after_scenario" in scenario.tags: | ||
cause_hook_failure() | ||
""" | ||
And a file named "behave.ini" with: | ||
""" | ||
[behave.userdata] | ||
behave.reporter.junit.show_timestamp = False | ||
behave.reporter.junit.show_hostname = False | ||
""" | ||
|
||
Scenario: Hook error in before_scenario() | ||
When I run "behave -f plain --junit features/before_scenario_failure.feature" | ||
Then it should fail with: | ||
""" | ||
0 scenarios passed, 1 failed, 0 skipped | ||
""" | ||
And the command output should contain: | ||
""" | ||
Scenario: A1 | ||
HOOK-ERROR in before_scenario: ZeroDivisionError: integer division or modulo by zero | ||
""" | ||
And the file "reports/TESTS-before_scenario_failure.xml" should contain: | ||
""" | ||
<testsuite errors="1" failures="0" name="before_scenario_failure.Alice" skipped="0" tests="1" | ||
""" | ||
And the file "reports/TESTS-before_scenario_failure.xml" should contain: | ||
""" | ||
<error message="HOOK-ERROR in before_scenario: ZeroDivisionError: integer division or modulo by zero" type="ZeroDivisionError"> | ||
""" | ||
And the file "reports/TESTS-before_scenario_failure.xml" should contain: | ||
""" | ||
File "features/environment.py", line 6, in before_scenario | ||
cause_hook_failure() | ||
File "features/environment.py", line 2, in cause_hook_failure | ||
1 / 0 # CAUSE: ZeroDivisionError | ||
""" | ||
And note that "the traceback is contained in the XML element <error/>" | ||
|
||
|
||
Scenario: Hook error in after_scenario() | ||
When I run "behave -f plain --junit features/after_scenario_failure.feature" | ||
Then it should fail with: | ||
""" | ||
0 scenarios passed, 1 failed, 0 skipped | ||
""" | ||
And the command output should contain: | ||
""" | ||
Scenario: B1 | ||
Given another step passes ... passed | ||
HOOK-ERROR in after_scenario: ZeroDivisionError: integer division or modulo by zero | ||
""" | ||
And the file "reports/TESTS-after_scenario_failure.xml" should contain: | ||
""" | ||
<testsuite errors="1" failures="0" name="after_scenario_failure.Bob" skipped="0" tests="1" | ||
""" | ||
And the file "reports/TESTS-after_scenario_failure.xml" should contain: | ||
""" | ||
<error message="HOOK-ERROR in after_scenario: ZeroDivisionError: integer division or modulo by zero" type="ZeroDivisionError"> | ||
""" | ||
And the file "reports/TESTS-after_scenario_failure.xml" should contain: | ||
""" | ||
File "features/environment.py", line 10, in after_scenario | ||
cause_hook_failure() | ||
File "features/environment.py", line 2, in cause_hook_failure | ||
1 / 0 # CAUSE: ZeroDivisionError | ||
""" | ||
And note that "the traceback is contained in the XML element <error/>" | ||
|