Permalink
Browse files

Messages for failures, skips and errors added

  • Loading branch information...
1 parent 440c4d6 commit 3fbd3b4fecdfeafc5576ec6cfa30ffc76dffc658 @AutomatedTester AutomatedTester committed Jun 1, 2011
Showing with 36 additions and 20 deletions.
  1. +15 −4 garmr.py
  2. +21 −16 test/test_reports.py
View
@@ -67,7 +67,8 @@ def write_results(self, file_name='garmr-results.xml', results=None):
def _format_results(self):
- testcase = """<testcase classname="" name="{testname}" time="{timetaken}"/>"""
+ testcase = """<testcase classname="" name="{testname}" time="{timetaken}" """
+ errs = '><{errtype}>{message}</{errtype}></testcase>'
formatted_results = ""
results = {"time_taken":0,
"errors" : 0,
@@ -81,10 +82,15 @@ def _format_results(self):
testname = res["name"],timetaken=res["time_taken"])
if res.has_key("errors"):
results["errors"] += 1
- if res.has_key("failed"):
+ formatted_results += errs.format(errtype="error", message=res["message"])
+ elif res.has_key("failed"):
results["failed"] += 1
- if res.has_key("skips"):
+ formatted_results += errs.format(errtype="failure", message=res["message"])
+ elif res.has_key("skips"):
results["skips"] += 1
+ formatted_results += errs.format(errtype="skipped", message=res["message"])
+ else:
+ formatted_results += "/>"
results["time_taken"] += res["time_taken"]
results["testcase"] = formatted_results
@@ -112,11 +118,14 @@ def xframe_checks(self):
logger.info("x-frame-options were correct")
except KeyError:
+ message = "x-frame-options were not found in headers"
result["failed"] = True
- logger.critical("x-frame-options were not found in headers")
+ result["message"] = message
+ logger.critical(message)
except AssertionError as e:
logger.error(str(e))
result["errors"] = True
+ result["message"] = str(e)
finish = datetime.now()
result["time_taken"] = self._total_seconds(start, finish)
logger.debug("Time Taken: %s:" % result["time_taken"])
@@ -142,6 +151,7 @@ def trace_checks(self):
except Exception, e:
logger.error(str(e))
result["errors"] = True
+ result["message"] = str(e)
finish = datetime.now()
result["time_taken"] = self._total_seconds(start, finish)
logger.debug("Time Taken: %s:" % result["time_taken"])
@@ -160,6 +170,7 @@ def redirect_checks(self):
except AssertionError, e:
logger.error(str(e))
result["errors"] = True
+ result["message"] = str(e)
finish = datetime.now()
result["time_taken"] = self._total_seconds(start, finish)
logger.debug("Time Taken: %s:" % result["time_taken"])
View
@@ -24,7 +24,7 @@ def test_reporter_formats_test_cases_with_no_errors_or_failures(self):
})
reporter = Reporter(tests_list)
result = reporter._format_results()
- assert result["testcase"] == """<testcase classname="" name="%s" time="%s"/>""" % \
+ assert result["testcase"] == """<testcase classname="" name="%s" time="%s" />""" % \
(tests_list[0]["name"], tests_list[0]["time_taken"])
assert result["time_taken"] == 1
assert result["errors"] == 0
@@ -41,9 +41,9 @@ def test_reporter_formats_2_test_cases_with_no_errors_or_failures(self):
})
reporter = Reporter(tests_list)
result = reporter._format_results()
- expected = """<testcase classname="" name="%s" time="%s"/>""" % \
+ expected = """<testcase classname="" name="%s" time="%s" />""" % \
(tests_list[0]["name"], tests_list[0]["time_taken"])
- expected += """<testcase classname="" name="%s" time="%s"/>""" % \
+ expected += """<testcase classname="" name="%s" time="%s" />""" % \
(tests_list[1]["name"], tests_list[1]["time_taken"])
assert result["testcase"] == expected, result["testcase"]
assert result["time_taken"] == 2
@@ -56,18 +56,20 @@ def test_reporter_formats_2_test_cases_with_mix_of_errors_or_failures(self):
tests_list = []
tests_list.append({"name":"error test",
"time_taken": 1,
- "errors" : True
+ "errors" : True,
+ "message" : "omg i errored",
})
tests_list.append({"name":"failure test",
"time_taken": 1,
- "failed" : True
+ "failed" : True,
+ "message": "Omg I failed",
})
reporter = Reporter(tests_list)
result = reporter._format_results()
- expected = """<testcase classname="" name="%s" time="%s"/>""" % \
- (tests_list[0]["name"], tests_list[0]["time_taken"])
- expected += """<testcase classname="" name="%s" time="%s"/>""" % \
- (tests_list[1]["name"], tests_list[1]["time_taken"])
+ expected = """<testcase classname="" name="%s" time="%s" ><error>%s</error></testcase>""" % \
+ (tests_list[0]["name"], tests_list[0]["time_taken"],tests_list[0]["message"])
+ expected += """<testcase classname="" name="%s" time="%s" ><failure>%s</failure></testcase>""" % \
+ (tests_list[1]["name"], tests_list[1]["time_taken"],tests_list[1]["message"])
assert result["testcase"] == expected, result["testcase"]
assert result["time_taken"] == 2
assert result["errors"] == 1
@@ -79,11 +81,12 @@ def test_reporter_formats_test_case_with_one_failure(self):
tests_list.append({"name":"failedtest",
"time_taken": 1,
"failed": True,
+ "message": "Omg I failed",
})
reporter = Reporter(tests_list)
result = reporter._format_results()
- assert result["testcase"] == """<testcase classname="" name="%s" time="%s"/>""" % \
- (tests_list[0]["name"], tests_list[0]["time_taken"])
+ assert result["testcase"] == """<testcase classname="" name="%s" time="%s" ><failure>%s</failure></testcase>""" % \
+ (tests_list[0]["name"], tests_list[0]["time_taken"],tests_list[0]["message"])
assert result["time_taken"] == 1
assert result["errors"] == 0
assert result["failed"] == 1
@@ -94,11 +97,12 @@ def test_reporter_formats_test_case_with_error(self):
tests_list.append({"name":"errorstest",
"time_taken": 1,
"errors": True,
+ "message": "Omg I errored"
})
reporter = Reporter(tests_list)
result = reporter._format_results()
- assert result["testcase"] == """<testcase classname="" name="%s" time="%s"/>""" % \
- (tests_list[0]["name"], tests_list[0]["time_taken"])
+ assert result["testcase"] == """<testcase classname="" name="%s" time="%s" ><error>%s</error></testcase>""" % \
+ (tests_list[0]["name"], tests_list[0]["time_taken"],tests_list[0]["message"])
assert result["time_taken"] == 1
assert result["errors"] == 1
assert result["failed"] == 0
@@ -109,11 +113,12 @@ def test_reporter_formats_test_case_with_skip(self):
tests_list.append({"name":"skipstest",
"time_taken": 1,
"skips": True,
+ "message": "Omg I skipped"
})
reporter = Reporter(tests_list)
result = reporter._format_results()
- assert result["testcase"] == """<testcase classname="" name="%s" time="%s"/>""" % \
- (tests_list[0]["name"], tests_list[0]["time_taken"])
+ assert result["testcase"] == """<testcase classname="" name="%s" time="%s" ><skipped>%s</skipped></testcase>""" % \
+ (tests_list[0]["name"], tests_list[0]["time_taken"],tests_list[0]["message"])
assert result["time_taken"] == 1
assert result["errors"] == 0
assert result["failed"] == 0
@@ -129,7 +134,7 @@ def test_that_reporter_writes_to_disk(self):
skips="{skips}" tests="{numtests}" time="{timetaken}">
{testresults}
</testsuite>"""
- testcase = """<testcase classname="" name="%s" time="%s"/>""" % \
+ testcase = """<testcase classname="" name="%s" time="%s" />""" % \
(tests_list[0]["name"], tests_list[0]["time_taken"])
expected = suite_xml.format(error=0, failure=0, skips=0, numtests=len(tests_list),

0 comments on commit 3fbd3b4

Please sign in to comment.