From 3daf71b2b593ef6de00ddc2ea440f13239d7c894 Mon Sep 17 00:00:00 2001 From: jpizarro Date: Wed, 18 Dec 2024 11:24:30 +0100 Subject: [PATCH] Fixed test_utils after rebasing --- .vscode/settings.json | 9 +++++++++ tests/utils/test_utils.py | 31 ++++++++++++++----------------- 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 886582e..806496d 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -59,6 +59,15 @@ "justMyCode": false, "args": ["export-entities-to-json"] }, + { + "name": "bds export-to-excel", + "type": "debugpy", + "request": "launch", + "cwd": "${workspaceFolder}", + "program": "${workspaceFolder}/.venv/bin/bam_data_store", + "justMyCode": false, + "args": ["export-entities-to-excel"] + }, ] }, } diff --git a/tests/utils/test_utils.py b/tests/utils/test_utils.py index d0952ba..da61983 100644 --- a/tests/utils/test_utils.py +++ b/tests/utils/test_utils.py @@ -12,12 +12,6 @@ ) -@pytest.fixture(autouse=True) -def clear_log_storage(): - """Fixture to clear the log storage before each test.""" - log_storage.clear() - - @pytest.mark.parametrize( 'directory_path, dir_exists', [ @@ -27,16 +21,18 @@ def clear_log_storage(): ('tests/data/tmp/', True), ], ) -def test_delete_and_create_dir(directory_path: str, dir_exists: bool): +def test_delete_and_create_dir( + cleared_log_storage: list, directory_path: str, dir_exists: bool +): """Tests the `delete_and_delete_dir` function.""" delete_and_create_dir(directory_path=directory_path, logger=logger) assert dir_exists == os.path.exists(directory_path) if dir_exists: shutil.rmtree(directory_path) # ! careful with this line else: - assert len(log_storage) == 1 - assert log_storage[0]['level'] == 'warning' - assert 'directory_path' in log_storage[0]['event'] + assert len(cleared_log_storage) == 1 + assert cleared_log_storage[0]['level'] == 'warning' + assert 'directory_path' in cleared_log_storage[0]['event'] @pytest.mark.parametrize( @@ -53,11 +49,8 @@ def test_delete_and_create_dir(directory_path: str, dir_exists: bool): ('./tests/data', [], 'No Python files found in the directory.', 'info'), # Python files found in the directory ( - './tests', + './tests/utils', [ - './tests/conftest.py', - './tests/metadata/test_entities.py', - './tests/metadata/test_definitions.py', './tests/utils/test_utils.py', ], None, @@ -66,13 +59,17 @@ def test_delete_and_create_dir(directory_path: str, dir_exists: bool): ], ) def test_listdir_py_modules( - directory_path: str, listdir: list[str], log_message: str, log_message_level: str + cleared_log_storage: list, + directory_path: str, + listdir: list[str], + log_message: str, + log_message_level: str, ): """Tests the `listdir_py_modules` function.""" result = listdir_py_modules(directory_path=directory_path, logger=logger) if not listdir: - assert log_storage[0]['event'] == log_message - assert log_storage[0]['level'] == log_message_level + assert cleared_log_storage[0]['event'] == log_message + assert cleared_log_storage[0]['level'] == log_message_level # when testing locally and with Github actions the order of the files is different --> `result` is sorted, so we also sort `listdir` assert result == sorted(listdir)