Commit 003a47ee by Gabriel Falcão

almost passing

parent fc71207c
...@@ -50,7 +50,15 @@ class StepDefinition(object): ...@@ -50,7 +50,15 @@ class StepDefinition(object):
"""Method that actually wrapps the call to step definition """Method that actually wrapps the call to step definition
callback. Sends step object as first argument callback. Sends step object as first argument
""" """
return self.function(self.step, *args, **kw) try:
ret = self.function(self.step, *args, **kw)
self.step.passed = True
except Exception, e:
self.step.failed = True
self.step.why = ReasonToFail(e)
raise e
return ret
class StepDescription(object): class StepDescription(object):
"""A simple object that holds filename and line number of a step """A simple object that holds filename and line number of a step
...@@ -105,9 +113,8 @@ class Step(object): ...@@ -105,9 +113,8 @@ class Step(object):
table_indentation = indentation + 2 table_indentation = indentation + 2
defined_at = None defined_at = None
ran = False ran = False
passed = False passed = None
failed = False failed = None
why = None
def __init__(self, sentence, remaining_lines, line=None, filename=None): def __init__(self, sentence, remaining_lines, line=None, filename=None):
self.sentence = sentence self.sentence = sentence
...@@ -191,20 +198,16 @@ class Step(object): ...@@ -191,20 +198,16 @@ class Step(object):
definitions""" definitions"""
matched, step_definition = self.pre_run(ignore_case) matched, step_definition = self.pre_run(ignore_case)
self.ran = True self.ran = True
try: kw = matched.groupdict()
kw = matched.groupdict()
if kw: if kw:
step_definition(**kw) step_definition(**kw)
else: else:
groups = matched.groups() groups = matched.groups()
step_definition(*groups) step_definition(*groups)
self.passed = True self.passed = True
except Exception, e: return True
self.why = ReasonToFail(e)
self.failed = True
raise
@classmethod @classmethod
def from_string(cls, string, with_file=None, original_string=None): def from_string(cls, string, with_file=None, original_string=None):
...@@ -310,10 +313,9 @@ class Scenario(object): ...@@ -310,10 +313,9 @@ class Scenario(object):
except AssertionError: except AssertionError:
steps_failed.append(step) steps_failed.append(step)
continue
except NoDefinitionFound, e: except NoDefinitionFound, e:
steps_undefined.append(e.step) steps_undefined.append(e.step)
continue
finally: finally:
for callback in CALLBACK_REGISTRY['step']['after_each']: for callback in CALLBACK_REGISTRY['step']['after_each']:
...@@ -562,7 +564,7 @@ class TotalResult(object): ...@@ -562,7 +564,7 @@ class TotalResult(object):
@property @property
def features_passed(self): def features_passed(self):
return len([result.passed for result in self.feature_results]) return len([result for result in self.feature_results if result.passed])
@property @property
def scenarios_ran(self): def scenarios_ran(self):
...@@ -570,4 +572,4 @@ class TotalResult(object): ...@@ -570,4 +572,4 @@ class TotalResult(object):
@property @property
def scenarios_passed(self): def scenarios_passed(self):
return len([result.passed for result in self.scenario_results]) return len([result for result in self.scenario_results if result.passed])
...@@ -30,10 +30,21 @@ def print_step_ran(step): ...@@ -30,10 +30,21 @@ def print_step_ran(step):
if step.data_list: if step.data_list:
sys.stdout.write("\033[A" * (len(step.data_list) + 1)) sys.stdout.write("\033[A" * (len(step.data_list) + 1))
sys.stdout.write("\033[A" + step.represent_string(step.sentence)) if step.defined_at:
sys.stdout.write("\033[A" + step.represent_string(step.sentence))
else:
sys.stdout.write(step.represent_string(step.sentence).rstrip() + " (undefined)\n")
if step.data_list: if step.data_list:
sys.stdout.write(step.represent_data_list()) sys.stdout.write(step.represent_data_list())
if step.failed:
print_spaced = lambda x: sys.stdout.write("%s%s\n" % (" " * step.indentation, x))
for line in step.why.traceback.splitlines():
print_spaced(line)
@before.each_scenario @before.each_scenario
def print_scenario_running(scenario): def print_scenario_running(scenario):
sys.stdout.write(scenario.represented()) sys.stdout.write(scenario.represented())
......
...@@ -2,7 +2,11 @@ Feature: Table Fail ...@@ -2,7 +2,11 @@ Feature: Table Fail
Scenario: See it fail Scenario: See it fail
Given I have a dumb step that passes Given I have a dumb step that passes
And this one fails And this one fails
Then this one will be skipped Then this one will be skipped
And this one will be skipped And this one will be skipped
And this one does not even has definition And this one does not even has definition
...@@ -27,6 +27,3 @@ def tof(step): ...@@ -27,6 +27,3 @@ def tof(step):
@step('this one will be skipped') @step('this one will be skipped')
def wbs(step): def wbs(step):
assert True assert True
...@@ -374,3 +374,46 @@ def test_output_with_success_colorful_with_table(): ...@@ -374,3 +374,46 @@ def test_output_with_success_colorful_with_table():
"\033[1;37m5 steps (\033[1;32m5 passed\033[1;37m)\033[0m\n" "\033[1;37m5 steps (\033[1;32m5 passed\033[1;37m)\033[0m\n"
) )
@with_setup(prepare_stdout)
def test_output_with_failed_colorless_with_table():
"Testing the colorless output of failed with table"
runner = Runner(feature_name('failed_table'), verbosity=3)
runner.run()
assert_stdout_lines(
"\n"
"Feature: Table Fail # tests/functional/output_features/failed_table/failed_table.feature:1\n"
"\n"
" Scenario: See it fail # tests/functional/output_features/failed_table/failed_table.feature:2\n"
" Given I have a dumb step that passes # tests/functional/output_features/failed_table/failed_table_steps.py:20\n"
"\033[A Given I have a dumb step that passes # tests/functional/output_features/failed_table/failed_table_steps.py:20\n"
" And this one fails # tests/functional/output_features/failed_table/failed_table_steps.py:24\n"
"\033[A And this one fails # tests/functional/output_features/failed_table/failed_table_steps.py:24\n"
" Traceback (most recent call last):\n"
' File "%(lettuce_core_file)s", line 54, in __call__\n'
" ret = self.function(self.step, *args, **kw)\n"
' File "%(step_file)s", line 25, in tof\n'
" assert False\n"
" AssertionError\n"
" Then this one will be skipped # tests/functional/output_features/failed_table/failed_table_steps.py:28\n"
"\033[A Then this one will be skipped # tests/functional/output_features/failed_table/failed_table_steps.py:28\n"
" And this one will be skipped # tests/functional/output_features/failed_table/failed_table_steps.py:28\n"
"\033[A And this one will be skipped # tests/functional/output_features/failed_table/failed_table_steps.py:28\n"
" And this one does not even has definition # tests/functional/output_features/failed_table/failed_table.feature:12 (undefined)\n"
"\n"
"1 feature (1 failed)\n"
"1 scenario (1 failed)\n"
"4 steps (1 failed, 1 skipped, 1 undefined, 1 passed)\n"
"\n"
"You can implement step definitions for undefined steps with these snippets:\n"
"\n"
"from lettuce import step\n"
"\n"
"@step(r'And this one does not even has definition')\n"
"def and_this_one_does_not_even_has_definition(step):\n"
" pass\n" % {
'lettuce_core_file':'/Users/gabriel.falcao/Projetos/lettuce/lettuce/core.py',
'step_file': '/Users/gabriel.falcao/Projetos/lettuce/tests/functional/output_features/failed_table/failed_table_steps.py'
}
)
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