Skip to content

Commit

Permalink
Merge pull request #303 from enewton/master
Browse files Browse the repository at this point in the history
Fix for issue #242 "xunit dies on undefined steps" WITH TESTS!
  • Loading branch information
gabrielfalcao committed Dec 12, 2012
2 parents b510787 + f5042fc commit 0b2fa47
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lettuce/plugins/xunit_output.py
Expand Up @@ -56,10 +56,12 @@ def create_test_case_step(step):
tc = doc.createElement("testcase")
tc.setAttribute("classname", classname)
tc.setAttribute("name", step.sentence)
tc.setAttribute("time", str(total_seconds((datetime.now() - step.started))))

if not step.ran:
if step.ran:
tc.setAttribute("time", str(total_seconds((datetime.now() - step.started))))
else:
tc.setAttribute("time", str(0))
skip=doc.createElement("skipped")
skip.setAttribute("type", "UndefinedStep(%s)" % step.sentence)
tc.appendChild(skip)

if step.failed:
Expand Down
@@ -0,0 +1,7 @@
Feature: Scenario with no steps
As a programmer
In order practise TDD
I want to write some scenarios before writing the steps

Scenario: Do nothing
Given I do nothing
Empty file.
24 changes: 24 additions & 0 deletions tests/functional/test_xunit_output.py
Expand Up @@ -86,6 +86,7 @@ def assert_correct_xml(filename, content):
assert_equals(1, len(called), "Function not called")
xunit_output.wrt_output = old


@with_setup(prepare_stdout, registry.clear)
def test_xunit_output_with_different_filename():
'Test xunit output with different filename'
Expand All @@ -105,3 +106,26 @@ def assert_correct_xml(filename, content):
xunit_output.wrt_output = old


@with_setup(prepare_stdout, registry.clear)
def test_xunit_output_with_no_steps():
'Test xunit output with no steps'
called = []
def assert_correct_xml(filename, content):
print filename
print content
called.append(True)
assert_xsd_valid(filename, content)
root = etree.fromstring(content)
assert_equals(root.get("tests"), "1")
assert_equals(root.find("testcase").get("name"), "Given I do nothing")
assert_equals(len(root.getchildren()), 1)
assert_equals(root.find("testcase/skipped").get("type"), "UndefinedStep(Given I do nothing)")
assert_equals(float(root.find("testcase").get("time")), 0)

old = xunit_output.wrt_output
xunit_output.wrt_output = assert_correct_xml
runner = Runner(feature_name('no_steps_defined'), enable_xunit=True)
runner.run()

assert_equals(1, len(called), "Function not called")
xunit_output.wrt_output = old

0 comments on commit 0b2fa47

Please sign in to comment.