Skip to content

Commit 82db363

Browse files
committed
Tests: Fixed flaky test.
1 parent a369f59 commit 82db363

File tree

1 file changed

+19
-18
lines changed

1 file changed

+19
-18
lines changed

tests/test_api/test_02_get_attr_value.py

+19-18
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ class GetEidAttrValue(common.APITest):
1818
@classmethod
1919
def setUpClass(cls) -> None:
2020
super().setUpClass()
21-
sleep(1)
21+
sleep(8)
22+
# Data must pass to DB before this request is processed
2223
cls.get_request("control/make_snapshots")
23-
sleep(6)
2424

2525
def test_unknown_entity_type(self):
2626
response = self.get_request(
@@ -84,23 +84,9 @@ def get_history_attr_value(self, path: str):
8484
return result
8585

8686
def test_attr_serialization(self):
87-
for data_type, valid in common.values["valid"].items():
88-
value = valid[-1] # Plain attribute has the latest sent value
89-
with self.subTest(data_type=data_type, v=value):
90-
path = TESTED_PATH.format(
91-
entity="test_entity_type",
92-
eid="test_entity_id",
93-
attr=f"test_attr_{data_type}",
94-
)
95-
expected = EntityEidAttrValueOrHistory(attr_type=1, current_value=value)
96-
result = self.get_entity_data(path, EntityEidAttrValueOrHistory)
97-
if expected != result:
98-
print(f"Expected: {expected}")
99-
print(f"Result: {result}")
100-
self.assertEqual(expected, result)
101-
87+
# Test first with `query_expected_value` to await snapshot
10288
for data_type, valid in common.observation_values["valid"].items():
103-
with self.subTest(data_type=data_type, v=value):
89+
with self.subTest(data_type=data_type, v=valid):
10490
path = TESTED_PATH.format(
10591
entity="test_entity_type",
10692
eid="test_entity_id",
@@ -115,3 +101,18 @@ def test_attr_serialization(self):
115101
attempts=50,
116102
delay_s=0.2,
117103
)
104+
105+
for data_type, valid in common.values["valid"].items():
106+
value = valid[-1] # Plain attribute has the latest sent value
107+
with self.subTest(data_type=data_type, v=value):
108+
path = TESTED_PATH.format(
109+
entity="test_entity_type",
110+
eid="test_entity_id",
111+
attr=f"test_attr_{data_type}",
112+
)
113+
expected = EntityEidAttrValueOrHistory(attr_type=1, current_value=value)
114+
result = self.get_entity_data(path, EntityEidAttrValueOrHistory)
115+
if expected != result:
116+
print(f"Expected: {expected}")
117+
print(f"Result: {result}")
118+
self.assertEqual(expected, result)

0 commit comments

Comments
 (0)