Commit 7a7b86c0 by Michael Edwards

Scenario Names now uses Reporter

parent 5b9e49ad
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
import os import os
from lettuce import core from lettuce import core
from lettuce.terrain import after from lettuce.terrain import after
from lettuce.terrain import before
from lettuce.plugins.reporter import Reporter from lettuce.plugins.reporter import Reporter
class DotReporter(Reporter): class DotReporter(Reporter):
...@@ -33,6 +34,7 @@ class DotReporter(Reporter): ...@@ -33,6 +34,7 @@ class DotReporter(Reporter):
reporter = DotReporter() reporter = DotReporter()
before.each_scenario(reporter.print_scenario_running)
after.each_scenario(reporter.print_scenario_ran) after.each_scenario(reporter.print_scenario_ran)
after.each_step(reporter.store_failed_step) after.each_step(reporter.store_failed_step)
after.all(reporter.print_end) after.all(reporter.print_end)
......
...@@ -15,6 +15,9 @@ class Reporter(object): ...@@ -15,6 +15,9 @@ class Reporter(object):
self.scenarios_and_its_fails[step.scenario] = step.why self.scenarios_and_its_fails[step.scenario] = step.why
self.failed_scenarios.append(step.scenario) self.failed_scenarios.append(step.scenario)
def print_scenario_running(self, scenario):
pass
def print_scenario_ran(self, scenario): def print_scenario_ran(self, scenario):
pass pass
......
...@@ -16,78 +16,32 @@ ...@@ -16,78 +16,32 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
import os import os
import sys
from lettuce import core from lettuce import core
from lettuce.terrain import after from lettuce.terrain import after
from lettuce.terrain import before from lettuce.terrain import before
from lettuce.plugins.reporter import Reporter
failed_scenarios = [] class NameReporter(Reporter):
scenarios_and_its_fails = {} def print_scenario_running(self, scenario):
self.wrt('%s ... ' % scenario.name)
def print_scenario_ran(self, scenario):
if scenario.passed:
self.wrt("OK")
elif scenario.failed:
reason = self.scenarios_and_its_fails[scenario]
if isinstance(reason.exception, AssertionError):
self.wrt("FAILED")
else:
self.wrt("ERROR")
self.wrt("\n")
def wrt(what): reporter = NameReporter()
if isinstance(what, unicode):
what = what.encode('utf-8')
sys.stdout.write(what)
before.each_scenario(reporter.print_scenario_running)
@before.each_scenario after.each_scenario(reporter.print_scenario_ran)
def print_scenario_running(scenario): after.each_step(reporter.store_failed_step)
wrt('%s ... ' % scenario.name) after.all(reporter.print_end)
@after.each_scenario
def print_scenario_ran(scenario):
if scenario.passed:
print "OK"
elif scenario.failed:
reason = scenarios_and_its_fails[scenario]
if isinstance(reason.exception, AssertionError):
print "FAILED"
else:
print "ERROR"
@after.each_step
def save_step_failed(step):
if step.failed and step.scenario not in failed_scenarios:
scenarios_and_its_fails[step.scenario] = step.why
failed_scenarios.append(step.scenario)
@after.all
def print_end(total):
if total.scenarios_passed < total.scenarios_ran:
print # just a line to separate things here
for scenario in failed_scenarios:
reason = scenarios_and_its_fails[scenario]
wrt(str(reason.step))
wrt("\n")
wrt(reason.traceback)
wrt("\n")
word = total.features_ran > 1 and "features" or "feature"
wrt("%d %s (%d passed)\n" % (
total.features_ran,
word,
total.features_passed))
word = total.scenarios_ran > 1 and "scenarios" or "scenario"
wrt("%d %s (%d passed)\n" % (
total.scenarios_ran,
word,
total.scenarios_passed))
steps_details = []
for kind in "failed", "skipped", "undefined":
attr = 'steps_%s' % kind
stotal = getattr(total, attr)
if stotal:
steps_details.append("%d %s" % (stotal, kind))
steps_details.append("%d passed" % total.steps_passed)
word = total.steps > 1 and "steps" or "step"
wrt("%d %s (%s)\n" % (total.steps, word, ", ".join(steps_details)))
def print_no_features_found(where): def print_no_features_found(where):
...@@ -95,5 +49,5 @@ def print_no_features_found(where): ...@@ -95,5 +49,5 @@ def print_no_features_found(where):
if not where.startswith(os.sep): if not where.startswith(os.sep):
where = '.%s%s' % (os.sep, where) where = '.%s%s' % (os.sep, where)
wrt('Oops!\n') reporter.wrt('Oops!\n')
wrt('could not find features at %s\n' % where) reporter.wrt('could not find features at %s\n' % where)
...@@ -908,6 +908,7 @@ def test_output_level_2_fail(): ...@@ -908,6 +908,7 @@ def test_output_level_2_fail():
assert_stdout_lines_with_traceback( assert_stdout_lines_with_traceback(
"See it fail ... FAILED\n" "See it fail ... FAILED\n"
"\n" "\n"
"\n"
"<Step: \"And this one fails\">\n" "<Step: \"And this one fails\">\n"
"Traceback (most recent call last):\n" "Traceback (most recent call last):\n"
' File "%(lettuce_core_file)s", line %(call_line)d, in __call__\n' ' File "%(lettuce_core_file)s", line %(call_line)d, in __call__\n'
...@@ -937,6 +938,7 @@ def test_output_level_2_error(): ...@@ -937,6 +938,7 @@ def test_output_level_2_error():
"It should pass ... OK\n" "It should pass ... OK\n"
"It should raise an exception different of AssertionError ... ERROR\n" "It should raise an exception different of AssertionError ... ERROR\n"
"\n" "\n"
"\n"
"<Step: \"Given my step that blows a exception\">\n" "<Step: \"Given my step that blows a exception\">\n"
"Traceback (most recent call last):\n" "Traceback (most recent call last):\n"
' File "%(lettuce_core_file)s", line %(call_line)d, in __call__\n' ' File "%(lettuce_core_file)s", line %(call_line)d, in __call__\n'
...@@ -1233,10 +1235,10 @@ def test_output_background_with_success_colorless(): ...@@ -1233,10 +1235,10 @@ def test_output_background_with_success_colorless():
' I want to automate its test # tests/functional/bg_features/simple/simple.feature:4\n' ' I want to automate its test # tests/functional/bg_features/simple/simple.feature:4\n'
'\n' '\n'
' Background:\n' ' Background:\n'
' Given the variable "X" holds 2 # tests/functional/test_runner.py:1219\n' ' Given the variable "X" holds 2 # tests/functional/test_runner.py:1221\n'
'\n' '\n'
' Scenario: multiplication changing the value # tests/functional/bg_features/simple/simple.feature:9\n' ' Scenario: multiplication changing the value # tests/functional/bg_features/simple/simple.feature:9\n'
' Given the variable "X" is equal to 2 # tests/functional/test_runner.py:1219\n' ' Given the variable "X" is equal to 2 # tests/functional/test_runner.py:1221\n'
'\n' '\n'
'1 feature (1 passed)\n' '1 feature (1 passed)\n'
'1 scenario (1 passed)\n' '1 scenario (1 passed)\n'
...@@ -1268,12 +1270,12 @@ def test_output_background_with_success_colorful(): ...@@ -1268,12 +1270,12 @@ def test_output_background_with_success_colorful():
'\033[1;37m I want to automate its test \033[1;30m# tests/functional/bg_features/simple/simple.feature:4\033[0m\n' '\033[1;37m I want to automate its test \033[1;30m# tests/functional/bg_features/simple/simple.feature:4\033[0m\n'
'\n' '\n'
'\033[1;37m Background:\033[0m\n' '\033[1;37m Background:\033[0m\n'
'\033[1;30m Given the variable "X" holds 2 \033[1;30m# tests/functional/test_runner.py:1254\033[0m\n' '\033[1;30m Given the variable "X" holds 2 \033[1;30m# tests/functional/test_runner.py:1256\033[0m\n'
'\033[A\033[1;32m Given the variable "X" holds 2 \033[1;30m# tests/functional/test_runner.py:1254\033[0m\n' '\033[A\033[1;32m Given the variable "X" holds 2 \033[1;30m# tests/functional/test_runner.py:1256\033[0m\n'
'\n' '\n'
'\033[1;37m Scenario: multiplication changing the value \033[1;30m# tests/functional/bg_features/simple/simple.feature:9\033[0m\n' '\033[1;37m Scenario: multiplication changing the value \033[1;30m# tests/functional/bg_features/simple/simple.feature:9\033[0m\n'
'\033[1;30m Given the variable "X" is equal to 2 \033[1;30m# tests/functional/test_runner.py:1254\033[0m\n' '\033[1;30m Given the variable "X" is equal to 2 \033[1;30m# tests/functional/test_runner.py:1256\033[0m\n'
'\033[A\033[1;32m Given the variable "X" is equal to 2 \033[1;30m# tests/functional/test_runner.py:1254\033[0m\n' '\033[A\033[1;32m Given the variable "X" is equal to 2 \033[1;30m# tests/functional/test_runner.py:1256\033[0m\n'
'\n' '\n'
'\033[1;37m1 feature (\033[1;32m1 passed\033[1;37m)\033[0m\n' '\033[1;37m1 feature (\033[1;32m1 passed\033[1;37m)\033[0m\n'
'\033[1;37m1 scenario (\033[1;32m1 passed\033[1;37m)\033[0m\n' '\033[1;37m1 scenario (\033[1;32m1 passed\033[1;37m)\033[0m\n'
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment