From 91cd08cdff110fbac8723c742777b228bdd3a853 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Mon, 24 Jul 2023 10:37:07 +0200 Subject: [PATCH] Adapted tests to use a locally started Redis instance. --- platypush/backend/__init__.py | 5 ++++- platypush/config/__init__.py | 8 ++++++-- tests/conftest.py | 7 ++++++- tests/etc/config_test.yaml | 14 +++++++------- 4 files changed, 23 insertions(+), 11 deletions(-) diff --git a/platypush/backend/__init__.py b/platypush/backend/__init__.py index 54aeadea0d..1afc4385be 100644 --- a/platypush/backend/__init__.py +++ b/platypush/backend/__init__.py @@ -443,7 +443,10 @@ class Backend(Thread, EventGenerator, ExtensionWithManifest): ) if self.zeroconf: - self.zeroconf.close() + try: + self.zeroconf.close() + except TimeoutError: + pass if self.zeroconf_info: self.bus.post( diff --git a/platypush/config/__init__.py b/platypush/config/__init__.py index 5b18b36f43..4e6e1ee53d 100644 --- a/platypush/config/__init__.py +++ b/platypush/config/__init__.py @@ -219,8 +219,12 @@ class Config: config = {} - with open(cfgfile, 'r') as fp: - file_config = yaml.safe_load(fp) + try: + with open(cfgfile, 'r') as fp: + file_config = yaml.safe_load(fp) + except FileNotFoundError: + print(f'Unable to open config file {cfgfile}') + return config if not file_config: return config diff --git a/tests/conftest.py b/tests/conftest.py index 3357f74752..017042aed7 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -30,7 +30,12 @@ def app(): logging.info('Starting Platypush test service') Config.init(config_file) - _app = Application(config_file=config_file, redis_queue='platypush-tests/bus') + _app = Application( + config_file=config_file, + redis_queue='platypush-tests/bus', + start_redis=True, + redis_port=16379, + ) Thread(target=_app.run).start() logging.info( 'Sleeping %d seconds while waiting for the daemon to start up', diff --git a/tests/etc/config_test.yaml b/tests/etc/config_test.yaml index 1859e0ae5f..2838d072dc 100644 --- a/tests/etc/config_test.yaml +++ b/tests/etc/config_test.yaml @@ -1,13 +1,13 @@ include: - - include/test_procedure.yaml + - include/test_procedure.yaml main.db: - engine: sqlite:////tmp/platypush-tests.db + engine: sqlite:////tmp/platypush-tests.db backend.http: - port: 8123 - num_workers: 1 - use_werkzeug_server: True + port: 8123 + num_workers: 1 + use_werkzeug_server: True -backend.redis: - disabled: False +redis: + port: 16379