From 456728c60492c8119aca45288b30eea5bb88adaa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Doktor?= Date: Fri, 22 Apr 2016 07:06:57 +0200 Subject: [PATCH] avocado.core.result: Handle incorrect number of total tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When the total number of tests is lower than number of executed tests, avocado reports incorrect number of tests. Let's increase the number of tests in such case. Signed-off-by: Lukáš Doktor --- avocado/core/result.py | 5 ++++- selftests/unit/test_jsonresult.py | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/avocado/core/result.py b/avocado/core/result.py index 252868ad..638bb1a1 100644 --- a/avocado/core/result.py +++ b/avocado/core/result.py @@ -137,7 +137,10 @@ class TestResult(object): self.failed + self.warned + self.skipped + self.interrupted) other_skipped_count = self.tests_total - valid_results_count - self.skipped += other_skipped_count + if other_skipped_count > 0: + self.skipped += other_skipped_count + else: + self.tests_total -= other_skipped_count def start_tests(self): """ diff --git a/selftests/unit/test_jsonresult.py b/selftests/unit/test_jsonresult.py index 07aab48c..93ae7988 100644 --- a/selftests/unit/test_jsonresult.py +++ b/selftests/unit/test_jsonresult.py @@ -85,5 +85,20 @@ class JSONResultTest(unittest.TestCase): check_item("[skip]", res["skip"], 4) check_item("[total]", res["total"], 13) + def testNegativeStatus(self): + def check_item(name, value, exp): + self.assertEqual(value, exp, "Result%s is %s and not %s\n%s" + % (name, value, exp, res)) + + self.test_result.tests_total = 0 + self.test_result.start_test(self.test1) + self.test_result.check_test(self.test1.get_state()) + self.test_result.end_tests() + res = json.loads(self.test_result.json) + check_item("[total]", res["total"], 1) + check_item("[skip]", res["skip"], 0) + check_item("[pass]", res["pass"], 1) + + if __name__ == '__main__': unittest.main() -- GitLab