Skip to content

Commit

Permalink
Nice error output is now always on
Browse files Browse the repository at this point in the history
  • Loading branch information
rlisagor committed Jun 6, 2011
1 parent e30899b commit d11a162
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 30 deletions.
11 changes: 9 additions & 2 deletions features/core.feature
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ Feature: Freshen core
raise Exception("FAIL")
Exception: FAIL
>> in "failing" # examples{sep}self_test{sep}features{sep}sample.feature:18
@one
Feature: Sample
@four
Scenario: Failing
given failing # examples{sep}self_test{sep}features{sep}sample.feature:18
----------------------------------------------------------------------
Ran 3 tests in {time}
Expand All @@ -69,7 +73,10 @@ Feature: Freshen core
raise Exception("FAIL")
Exception: FAIL
>> in "failing without a table" # examples{sep}self_test{sep}features{sep}outline_sample.feature:6
Feature: Outline Sample
Scenario: Test state
given failing without a table # examples/self_test/features/outline_sample.feature:6
given passing without a table # examples/self_test/features/outline_sample.feature:7
----------------------------------------------------------------------
Ran 4 tests in {time}
Expand Down
6 changes: 3 additions & 3 deletions features/error_steps.feature
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ Feature: Error steps
In order to speed up development
It is useful to see a verbose report of which step has failed

Scenario: Error steps
When I run nose -v --tags @one --error-steps examples/self_test
Then it should fail with
Scenario: Colorized output
When I run nose -v --tags @one examples/self_test
Then it should fail with colorized output
"""
Sample: Missing ... UNDEFINED: "missing" # examples{sep}self_test{sep}features{sep}sample.feature:7
Sample: Passing ... ok
Expand Down
8 changes: 6 additions & 2 deletions features/list_undefined.feature
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Feature: List undefined steps

Scenario: List undefined
When I run nose -v --tags @one --list-undefined examples/self_test
Then it should fail with
Then it should fail with colorized output
"""
Sample: Missing ... UNDEFINED: "missing" # examples{sep}self_test{sep}features{sep}sample.feature:7
Sample: Passing ... ok
Expand All @@ -20,7 +20,11 @@ Feature: List undefined steps
raise Exception("FAIL")
Exception: FAIL
>> in "failing" # examples{sep}self_test{sep}features{sep}sample.feature:18
@one
Feature: Sample
@four
Scenario: Failing
given failing  # examples{sep}self_test{sep}features{sep}sample.feature:18
======================================================================
Tests with undefined steps
Expand Down
13 changes: 11 additions & 2 deletions features/steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ def check_outcome(exp_status):
elif scc.status != 0:
raise Exception("Failed with exit status %d\nOUTPUT:\n%s" % (scc.status, scc.output))

@Then("^it should (pass|fail) with$")
def check_outcome_with(exp_output, exp_status):
def _check_outcome_with(exp_output, exp_status):
run_steps("Then it should %s" % exp_status)

exp_output = exp_output.replace("{cwd}", scc.cwd)
Expand All @@ -67,3 +66,13 @@ def check_outcome_with(exp_output, exp_status):
exp_output = exp_output.replace("{traceback_trace}", scc.traceback)
assert_equals(exp_output, scc.output)

@Then("^it should (pass|fail) with$")
def check_outcome_with(exp_output, exp_status):
# Strip color codes out first, we don't care
scc.output = re.sub("\033\\[[0-9]*m", '', scc.output)
return _check_outcome_with(exp_output, exp_status)

@Then("^it should (pass|fail) with colorized output$")
def check_outcome_with_colorized(exp_output, exp_status):
return _check_outcome_with(exp_output, exp_status)

12 changes: 10 additions & 2 deletions features/tagging.feature
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ Feature: Tagging
raise Exception("FAIL")
Exception: FAIL
>> in "failing" # examples{sep}self_test{sep}features{sep}sample.feature:18
@one
Feature: Sample
@four
Scenario: Failing
given failing # examples{sep}self_test{sep}features{sep}sample.feature:18
----------------------------------------------------------------------
Ran 3 tests in {time}
Expand All @@ -56,7 +60,11 @@ Feature: Tagging
raise Exception("FAIL")
Exception: FAIL
>> in "failing" # examples{sep}self_test{sep}features{sep}sample.feature:18
@one
Feature: Sample
@four
Scenario: Failing
given failing # examples{sep}self_test{sep}features{sep}sample.feature:18
----------------------------------------------------------------------
Ran 1 test in {time}
Expand Down
28 changes: 9 additions & 19 deletions freshen/noseplugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,23 +125,18 @@ def options(self, parser, env):
"match the given tags. Should be a comma-separated "
"list. Each tag can be prefixed with a ~ to negate "
"[NOSE_FRESHEN_TAGS]")
parser.add_option('--language', action="store", dest='language',
default='en',
help='Change the language used when reading the feature files',
)
parser.add_option('--language',
action="store",
dest='language',
default='en',
help='Change the language used when reading the feature files')
parser.add_option('--list-undefined',
action="store_true",
default=env.get('NOSE_FRESHEN_LIST_UNDEFINED')=='1',
dest="list_undefined",
help="Make a report of all undefined steps that "
"freshen encounters when running scenarios. "
"[NOSE_FRESHEN_LIST_UNDEFINED]")
parser.add_option('--error-steps',
action="store_true",
default=env.get('NOSE_FRESHEN_ERROR_STEPS')=='1',
dest='error_steps',
help="Show the location of steps that fail/error. "
"[NOSE_FRESHEN_ERROR_STEPS]")

def configure(self, options, config):
super(FreshenNosePlugin, self).configure(options, config)
Expand All @@ -156,7 +151,6 @@ def configure(self, options, config):
self.undefined_steps = []
else:
self.undefined_steps = None
self.error_steps = options.error_steps

def wantDirectory(self, dirname):
if not os.path.exists(os.path.join(dirname, ".freshenignore")):
Expand Down Expand Up @@ -230,15 +224,11 @@ def formatFailure(self, test, err):
ec, ev, tb = err
if ec is ExceptionWrapper and isinstance(ev, Exception):
orig_ec, orig_ev, orig_tb = ev.e
if self.error_steps:
message = "%s\n\n%s" % (str(orig_ev), self._formatSteps(test, ev.step))
return (orig_ec, message, orig_tb)
else:
return (orig_ec, str(orig_ev) + '\n\n>> in "%s" # %s' % (ev.step.match, ev.step.source_location()), orig_tb)
message = "%s\n\n%s" % (str(orig_ev), self._formatSteps(test, ev.step))
return (orig_ec, message, orig_tb)
elif not ec is UndefinedStepImpl and hasattr(test.test, 'last_step'):
if self.error_steps:
message = "%s\n\n%s" % (str(ev), self._formatSteps(test, test.test.last_step))
return (ec, message, tb)
message = "%s\n\n%s" % (str(ev), self._formatSteps(test, test.test.last_step))
return (ec, message, tb)

formatError = formatFailure

Expand Down

0 comments on commit d11a162

Please sign in to comment.