From b3a3ab73f4334c184048ea757bcf0cfcf149ce5c Mon Sep 17 00:00:00 2001 From: Kevin Stone Date: Sun, 3 Mar 2013 14:10:36 -0800 Subject: [PATCH 1/2] Added failing test for `xunit_output` when using Background sections. Signed-off-by: Kevin Stone --- tests/functional/test_xunit_output.py | 38 ++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/tests/functional/test_xunit_output.py b/tests/functional/test_xunit_output.py index 7dfe02573..6b621ed8c 100644 --- a/tests/functional/test_xunit_output.py +++ b/tests/functional/test_xunit_output.py @@ -26,7 +26,7 @@ from lettuce import Runner from lettuce import xunit_output from lxml import etree -from tests.functional.test_runner import feature_name +from tests.functional.test_runner import feature_name, bg_feature_name from tests.asserts import prepare_stdout @@ -158,3 +158,39 @@ 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_background_section(): + 'Test xunit output with a background section in the feature' + called = [] + + def assert_correct_xml(filename, content): + called.append(True) + assert_xsd_valid(filename, content) + root = etree.fromstring(content) + assert_equals(root.get("tests"), "1") + assert_equals(root.get("failures"), "0") + assert_equals(len(root.getchildren()), 2) + + passed1, passed2 = root.findall("testcase") + assert_equals(passed1.get("name"), 'Given the variable "X" holds 2') + assert_true(float(passed1.get("time")) > 0) + assert_equals(passed2.get("name"), 'Given the variable "X" is equal to 2') + assert_true(float(passed2.get("time")) > 0) + + from lettuce import step + + @step(ur'the variable "(\w+)" holds (\d+)') + @step(ur'the variable "(\w+)" is equal to (\d+)') + def just_pass(step, *args): + pass + + filename = bg_feature_name('simple') + old = xunit_output.wrt_output + xunit_output.wrt_output = assert_correct_xml + runner = Runner(filename, enable_xunit=True) + runner.run() + + assert_equals(1, len(called), "Function not called") + xunit_output.wrt_output = old From f179e7e8b7521ee69e19694e0fb14ed0657748f7 Mon Sep 17 00:00:00 2001 From: Kevin Stone Date: Sun, 3 Mar 2013 14:11:43 -0800 Subject: [PATCH 2/2] Updated `xunit_output` to correctly output steps executed in a background section in addition to scenarios. Signed-off-by: Kevin Stone --- lettuce/plugins/xunit_output.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lettuce/plugins/xunit_output.py b/lettuce/plugins/xunit_output.py index 52433b9dd..0933159a4 100644 --- a/lettuce/plugins/xunit_output.py +++ b/lettuce/plugins/xunit_output.py @@ -50,10 +50,12 @@ def time_step(step): @after.each_step def create_test_case_step(step): - if step.scenario.outlines: + parent = step.scenario or step.background + if getattr(parent, 'outlines', None): return - - classname = utf8_string(u"%s : %s" % (step.scenario.feature.name, step.scenario.name)) + + name = getattr(parent, 'name', 'Background') # Background sections are nameless + classname = utf8_string(u"%s : %s" % (parent.feature.name, name)) tc = doc.createElement("testcase") tc.setAttribute("classname", classname) tc.setAttribute("name", step.sentence.encode('utf-8'))