Fix random unit test failures

As per https://bugs.debian.org/1029646, Cloudkitty often fails to build
as it fails its unit tests during the package build. This error happens
randomly. Sometimes it fails, sometimes it does not fail, but it's
clearly a false positive, because we don't really want the test to fail
in such case.

This patch makes it a lot less likely (10 times less) to happen by
increasing the tolerance.

Change-Id: If217a639f9af1e2693e6a132e46033df6bf96415
(cherry picked from commit b460fd937f)
This commit is contained in:
Thomas Goirand 2023-07-06 08:46:45 +02:00 committed by Pierre Riteau
parent a6aaa1101a
commit 119e8577b8

View File

@ -104,11 +104,11 @@ class StorageUnitTest(TestCase):
returned_total = round(
sum(r.get('rate', r.get('price')) for r in total['results']), 5)
self.assertLessEqual(
abs(expected_total - float(returned_total)), 0.00001)
abs(expected_total - float(returned_total)), 0.0001)
returned_qty = round(sum(r['qty'] for r in total['results']), 5)
self.assertLessEqual(
abs(expected_qty - float(returned_qty)), 0.00001)
abs(expected_qty - float(returned_qty)), 0.0001)
def test_get_total_all_scopes_all_periods(self):
expected_total, expected_qty, _ = self._expected_total_qty_len(
@ -193,24 +193,24 @@ class StorageUnitTest(TestCase):
abs(round(
float(first_element.get('rate', first_element.get('price')))
- expected_total_first, 5)),
0.00001,
0.0001,
)
second_element = total['results'][1]
self.assertLessEqual(
abs(round(
float(second_element.get('rate', second_element.get('price')))
- expected_total_second, 5)),
0.00001,
0.0001,
)
self.assertLessEqual(
abs(round(float(total['results'][0]['qty'])
- expected_qty_first, 5)),
0.00001,
0.0001,
)
self.assertLessEqual(
abs(round(float(total['results'][1]['qty'])
- expected_qty_second, 5)),
0.00001,
0.0001,
)
def test_get_total_all_scopes_one_period_groupby_project_id(self):
@ -236,23 +236,23 @@ class StorageUnitTest(TestCase):
self.assertLessEqual(
abs(round(float(first_entry.get('rate', first_entry.get('price')))
- expected_total_first, 5)),
0.00001,
0.0001,
)
self.assertLessEqual(
abs(round(
float(second_entry.get('rate', second_entry.get('price')))
- expected_total_second, 5)),
0.00001,
0.0001,
)
self.assertLessEqual(
abs(round(float(total['results'][0]['qty'])
- expected_qty_first, 5)),
0.00001,
0.0001,
)
self.assertLessEqual(
abs(round(float(total['results'][1]['qty'])
- expected_qty_second, 5)),
0.00001,
0.0001,
)
def test_get_total_all_scopes_all_periods_groupby_type_paginate(self):