Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'ISSUE-139-gherkin-terminal-reporter' of git://github.co…
…m/spinus/pytest-bdd into ISSUE-139-gherkin-terminal-reporter
- Loading branch information
Showing
7 changed files
with
434 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,11 @@ | ||
Changelog | ||
========= | ||
|
||
2.18.0 | ||
------ | ||
|
||
- Add gherkin terminal reporter (spinus + thedrow) | ||
|
||
2.17.1 | ||
------ | ||
|
||
|
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,98 @@ | ||
# -*- encoding: utf-8 -*- | ||
|
||
from _pytest.terminal import TerminalReporter | ||
|
||
|
||
def add_options(parser): | ||
group = parser.getgroup("terminal reporting", "reporting", after="general") | ||
group._addoption( | ||
'--gherkin-terminal-reporter', | ||
action="store_true", | ||
dest="gherkin_terminal_reporter", | ||
default=False, | ||
help=( | ||
"enable gherkin output" | ||
) | ||
) | ||
|
||
|
||
def configure(config): | ||
if config.option.gherkin_terminal_reporter: | ||
# Get the standard terminal reporter plugin and replace it with our | ||
current_reporter = config.pluginmanager.getplugin('terminalreporter') | ||
if current_reporter.__class__ != TerminalReporter: | ||
raise Exception("gherkin-terminal-reporter is not compatibile with any other terminal reporter." | ||
"You can use only one terminal reporter." | ||
"Currently '{0}' is used." | ||
"Please decide to use one by deactivating {0} or gherkin-terminal-reporter." | ||
.format(current_reporter.__class__)) | ||
gherkin_reporter = GherkinTerminalReporter(config) | ||
config.pluginmanager.unregister(current_reporter) | ||
config.pluginmanager.register(gherkin_reporter, 'terminalreporter') | ||
if config.pluginmanager.getplugin("dsession"): | ||
raise Exception("gherkin-terminal-reporter is not compatible with 'xdist' plugin.") | ||
|
||
|
||
class GherkinTerminalReporter(TerminalReporter): | ||
|
||
def __init__(self, config): | ||
TerminalReporter.__init__(self, config) | ||
|
||
def pytest_runtest_logstart(self, nodeid, location): | ||
# Prevent locationline from being printed since we already | ||
# show the module_name & in verbose mode the test name. | ||
pass | ||
|
||
def pytest_runtest_logreport(self, report): | ||
rep = report | ||
res = self.config.hook.pytest_report_teststatus(report=rep) | ||
cat, letter, word = res | ||
|
||
if not letter and not word: | ||
# probably passed setup/teardown | ||
return | ||
|
||
if isinstance(word, tuple): | ||
word, word_markup = word | ||
else: | ||
if rep.passed: | ||
word_markup = {'green': True} | ||
elif rep.failed: | ||
word_markup = {'red': True} | ||
elif rep.skipped: | ||
word_markup = {'yellow': True} | ||
feature_markup = {'blue': True} | ||
scenario_markup = word_markup | ||
|
||
if self.verbosity <= 0: | ||
return TerminalReporter.pytest_runtest_logreport(self, rep) | ||
elif self.verbosity == 1: | ||
if hasattr(report, 'scenario'): | ||
self.ensure_newline() | ||
self._tw.write('Feature: ', **feature_markup) | ||
self._tw.write(report.scenario['feature']['name'], **feature_markup) | ||
self._tw.write('\n') | ||
self._tw.write(' Scenario: ', **scenario_markup) | ||
self._tw.write(report.scenario['name'], **scenario_markup) | ||
self._tw.write(' ') | ||
self._tw.write(word, **word_markup) | ||
self._tw.write('\n') | ||
else: | ||
return TerminalReporter.pytest_runtest_logreport(self, rep) | ||
elif self.verbosity > 1: | ||
if hasattr(report, 'scenario'): | ||
self.ensure_newline() | ||
self._tw.write('Feature: ', **feature_markup) | ||
self._tw.write(report.scenario['feature']['name'], **feature_markup) | ||
self._tw.write('\n') | ||
self._tw.write(' Scenario: ', **scenario_markup) | ||
self._tw.write(report.scenario['name'], **scenario_markup) | ||
self._tw.write('\n') | ||
for step in report.scenario['steps']: | ||
self._tw.write(' {} {}\n'.format(step['keyword'], | ||
step['name']), **scenario_markup) | ||
self._tw.write(' ' + word, **word_markup) | ||
self._tw.write('\n\n') | ||
else: | ||
return TerminalReporter.pytest_runtest_logreport(self, rep) | ||
self.stats.setdefault(cat, []).append(rep) |
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,42 @@ | ||
Feature: Gherkin terminal reporter | ||
|
||
Scenario: Should default output be the same as regular terminal reporter | ||
Given there is gherkin scenario implemented | ||
When tests are run | ||
Then output must be formatted the same way as regular one | ||
|
||
Scenario: Should verbose mode enable displaying feature and scenario names rather than test names in a single line | ||
Given there is gherkin scenario implemented | ||
When tests are run with verbose mode | ||
Then output should contain single line feature description | ||
And output should contain single line scenario description | ||
|
||
Scenario: Should verbose mode preserve displaying of regular tests as usual | ||
Given there is non-gherkin scenario implemented | ||
When tests are run with verbose mode | ||
Then output must be formatted the same way as regular one | ||
|
||
Scenario: Should double verbose mode enable displaying of full gherkin scenario description | ||
Given there is gherkin scenario implemented | ||
When tests are run with very verbose mode | ||
Then output must contain full gherkin scenario description | ||
|
||
Scenario: Should error message be displayed when no scenario is found | ||
Given there is gherkin scenario without implementation | ||
When tests are run with any verbosity mode | ||
Then output contains error about missing scenario implementation | ||
|
||
Scenario: Should error message be displayed when no step is found | ||
Given there is gherkin scenario partially implemented | ||
When tests are run with any verbosity mode | ||
Then output contains error about missing step implementation | ||
|
||
Scenario: Should error message be displayed when error occurs during test execution | ||
Given there is gherkin scenario with broken implementation | ||
When tests are run with any verbosity mode | ||
Then output contains error about missing scenario implementation | ||
|
||
Scenario: Should local variables be displayed when --showlocals option is used | ||
Given there is gherkin scenario with broken implementation | ||
When tests are run with --showlocals | ||
Then error traceback contains local variable descriptions |
Oops, something went wrong.