Skip to content

Fix: repair ignored test files - #1241

Open
payalrvs3 wants to merge 1 commit into
devanshi14malhotra:mainfrom
payalrvs3:fix/804-repair-ignored-test-files
Open

payalrvs3 wants to merge 1 commit into
devanshi14malhotra:mainfrom
payalrvs3:fix/804-repair-ignored-test-files

Conversation

@payalrvs3

Copy link
Copy Markdown
Contributor

Description

Repairs all 5 test files that were silently ignored in CI, as reported in #804. Each fix targets the root cause rather than patching symptoms.

Changes made

File What changed
backend/requirements.txt Added beautifulsoup4, flask-caching, vaderSentiment
backend/cache_service.py Split redis/flask_caching imports into separate try blocks; added Cache = None fallback and early-return guard so caching degrades gracefully when flask-caching is absent
tests/conftest.py Added stubs for magic, spine_generator, vaderSentiment, vaderSentiment.vaderSentiment, nltk.corpus so tests run on Windows and without optional native libraries
tests/test_purchase_links.py Removed module-level from app import app and local client fixture that caused a double-import of backend/app.py, producing a broken second Flask instance and 404 responses; now uses conftest's properly-initialised client
tests/test_env_validation.py Replaced os.environ.clear() + manual restore pattern with monkeypatch.setenv/delenv and monkeypatch.delitem(sys.modules, 'config') for proper per-test isolation
tests/test_llm.py Full rewrite - original file had only print statements and collected 0 pytest items; replaced with TestIsAvailable, TestGenerateText, and TestLLMServiceSingleton classes using mocks
.github/workflows/ci.yml Added flask-caching to install step; removed 5 --ignore flags so all repaired tests run in CI

Root causes fixed

  • test_mood_cache_db: beautifulsoup4 and vaderSentiment installed ad-hoc in CI but missing from requirements.txt
  • test_category_cache: redis and flask_caching were in the same try block - import redis failing meant Cache was never defined, disabling caching entirely and breaking cache-hit assertions
  • test_purchase_links: from app import app at module level created a second Flask instance (sys.modules['app'] vs sys.modules['backend.app']), corrupting SQLAlchemy state → 404
  • test_env_validation: os.environ.clear() wiped system env vars mid-test; no sys.modules isolation between tests leaked stale config state
  • test_llm: File contained only print() statements - not a pytest test at all

Related Issue

Fixes #804

Type of Change

  • Bug Fix

Testing

Ran full test suite locally:

Signed-off-by: Payalrvs0310@gmail.com <Payalrvs0310@gmail.com>
@netlify

netlify Bot commented Jun 8, 2026 •

Copy link
Copy Markdown

❌ Deploy Preview for bibliodrift-dm failed. Why did it fail? →

Name Link
🔨 Latest commit 78c368f
🔍 Latest deploy log https://app.netlify.com/projects/bibliodrift-dm/deploys/6a266f905b0ee50008f147f5

@mayank-dev-15 mayank-dev-15 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good fix - repairing ignored test files ensures test coverage is maintained. LGTM.

@RudraMalvankar RudraMalvankar left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on re-enabling the previously ignored test suites.

The overall direction looks good and the added test coverage is valuable. I left a comment regarding the cache initialization path in cache_service.py, as it may lead to self.cache being unset when flask-caching is unavailable.

Other than that, the test cleanup and CI updates look reasonable.

Comment thread backend/cache_service.py
cache_config['CACHE_TYPE'] = 'SimpleCache'
logger.info("Using simple in-memory cache (not recommended for production)")

if Cache is None:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Returning early here leaves self.cache unset. Downstream code that assumes self.cache exists may raise an AttributeError. Would it be safer to initialize a fallback cache implementation or explicitly set self.cache = None before returning?

@payalrvs3

Copy link
Copy Markdown
Contributor Author

@RudraMalvankar, Thanks for looking closely! self.cache is already initialised to None in __init__ before init_app is ever called, so the early return leaves it in the same state it would be in if we assigned it explicitly. Every downstream method (get, set, delete) also guards with if not self.cache: return None/False, so there's no AttributeError risk. Happy to add the explicit assignment if you'd prefer it for readability, but the behaviour is identical either way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Multiple test files failing due to missing dependencies and pre-existing bugs

3 participants