Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix for issue #242 "xunit dies on undefined steps"

  • Loading branch information...
commit f5042fc12705d9043adebe307381197fe1f10cd8 1 parent b510787
enewton authored
View
8 lettuce/plugins/xunit_output.py
@@ -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:
View
7 tests/functional/output_features/no_steps_defined/no_steps_defined.feature
@@ -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
View
0  tests/functional/output_features/no_steps_defined/no_steps_defined_steps.py
No changes.
View
24 tests/functional/test_xunit_output.py
@@ -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'
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.