diff --git a/src/monitoring/tests/test_unitary.py b/src/monitoring/tests/test_unitary.py index 654614205b5e2da459b72358b42293c207f95072..563709aee4002ee2955739a4e476cb5ad6926e67 100644 --- a/src/monitoring/tests/test_unitary.py +++ b/src/monitoring/tests/test_unitary.py @@ -226,6 +226,18 @@ def ingestion_data(kpi_id_int): kpi_value) sleep(0.1) +################################################## +# Prepare Environment, should be the first test +################################################## + +def test_prepare_environment( + context_client : ContextClient, # pylint: disable=redefined-outer-name,unused-argument +): + context_id = json_context_id(DEFAULT_CONTEXT_NAME) + context_client.SetContext(Context(**json_context(DEFAULT_CONTEXT_NAME))) + context_client.SetTopology(Topology(**json_topology(DEFAULT_TOPOLOGY_NAME, context_id=context_id))) + + ########################### # Tests Implementation ########################### @@ -601,10 +613,6 @@ def test_listen_events( events_collector = EventsDeviceCollector(metrics_db.name_mapping) events_collector.start() - context_id = json_context_id(DEFAULT_CONTEXT_NAME) - context_client.SetContext(Context(**json_context(DEFAULT_CONTEXT_NAME))) - context_client.SetTopology(Topology(**json_topology(DEFAULT_TOPOLOGY_NAME, context_id=context_id))) - LOGGER.info('Adding Device {:s}'.format(DEVICE_DEV1_UUID)) device_with_connect_rules = copy.deepcopy(DEVICE_DEV1) device_with_connect_rules['device_config']['config_rules'].extend(DEVICE_DEV1_CONNECT_RULES) @@ -629,11 +637,17 @@ def test_listen_events( assert len(kpi_id_list) > 0 device_client.DeleteDevice(response) + events_collector.stop() + + LOGGER.warning('test_listen_events end') + +################################################## +# Cleanup Environment, should be the last test +################################################## +def test_cleanup_environment( + context_client : ContextClient, # pylint: disable=redefined-outer-name,unused-argument +): context_id = json_context_id(DEFAULT_CONTEXT_NAME) context_client.RemoveTopology(TopologyId(**json_topology_id(DEFAULT_TOPOLOGY_NAME, context_id=context_id))) context_client.RemoveContext(ContextId(**context_id)) - - events_collector.stop() - - LOGGER.warning('test_listen_events end')