From 324f09cf9febebf0d864d6874b593f5836856b19 Mon Sep 17 00:00:00 2001 From: "hsparks.codes" Date: Fri, 28 Nov 2025 05:04:00 +0100 Subject: [PATCH] fix: Update tests to handle openpyxl color format and ContextVar - Fix header color assertion to check only RGB values (not alpha channel) - Remove ContextVar mock as it cannot be patched in Python 3.11+ - All 17 tests now passing successfully --- tests/test_excel_store.py | 3 ++- tests/test_store_factory.py | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/test_excel_store.py b/tests/test_excel_store.py index a32ddff..18b55d4 100644 --- a/tests/test_excel_store.py +++ b/tests/test_excel_store.py @@ -143,7 +143,8 @@ class TestExcelStoreBase: # Check header formatting header_cell = excel_store.contents_sheet.cell(row=1, column=1) assert header_cell.font.bold is True - assert header_cell.fill.start_color.rgb == "FF366092" + # RGB color may have different prefix (00 or FF), check the actual color part + assert header_cell.fill.start_color.rgb[-6:] == "366092" def test_empty_sheets_removed(self, excel_store): """Test that empty sheets are removed on flush""" diff --git a/tests/test_store_factory.py b/tests/test_store_factory.py index 13ac4fc..ada123b 100644 --- a/tests/test_store_factory.py +++ b/tests/test_store_factory.py @@ -51,9 +51,9 @@ class TestXhsStoreFactory: assert isinstance(store, XhsMongoStoreImplement) @patch('config.SAVE_DATA_OPTION', 'excel') - @patch('var.crawler_type_var.get', return_value='search') - def test_create_excel_store(self, mock_crawler_type): + def test_create_excel_store(self): """Test creating Excel store""" + # ContextVar cannot be mocked, so we test with actual value store = XhsStoreFactory.create_store() assert isinstance(store, XhsExcelStoreImplement)