Skip to content

Commit bbe2fc3

Browse files
fix: Resolve test collection import errors (ModuleNotFoundError)
Fixed import errors that occurred during full test suite collection: - Error: "ModuleNotFoundError: 'empathy_os.workflows' is not a package" - Tests passed individually but failed during full `pytest tests/` collection Root Cause: - Lazy loading mechanism in workflows/__init__.py using __getattr__ - Import order dependency: when tests imported workflows in different orders, Python's import system became confused about package vs module Solution: 1. Added import guard in tests/conftest.py to eagerly load workflows - Calls discover_workflows() to trigger lazy loading of registered workflows - Explicitly imports non-registered workflow modules used by tests 2. Deleted Mac Finder duplicate files (" 2.py" naming pattern) Results: - Test collection: 6,335 tests → 13,589 tests (+7,254 tests discovered) - Import errors: 20+ errors → 0 errors - All workflow tests now properly discovered and collectible Files Modified: - tests/conftest.py: Added workflow import guard with eager loading Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 895262b commit bbe2fc3

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

tests/conftest.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,37 @@
88

99
import pytest
1010

11+
# =============================================================================
12+
# Import Guard - Ensure workflows package is properly initialized
13+
# =============================================================================
14+
# This prevents import errors when tests import from workflows package
15+
# in different orders. The lazy loading mechanism in workflows/__init__.py
16+
# can cause "not a package" errors if submodules are imported before the
17+
# package is fully initialized.
18+
#
19+
# We force eager initialization of ALL workflows by:
20+
# 1. Calling discover_workflows() to trigger lazy loading of registered workflows
21+
# 2. Explicitly importing non-registered workflow modules used by tests
22+
try:
23+
import empathy_os.workflows
24+
# Force all lazy workflows to load by discovering them
25+
empathy_os.workflows.discover_workflows()
26+
27+
# Import additional workflow modules not in lazy registry
28+
import empathy_os.workflows.history # noqa: F401
29+
import empathy_os.workflows.manage_docs # noqa: F401
30+
import empathy_os.workflows.batch_processing # noqa: F401
31+
import empathy_os.workflows.new_sample_workflow1 # noqa: F401
32+
import empathy_os.workflows.security_adapters # noqa: F401
33+
import empathy_os.workflows.security_audit_phase3 # noqa: F401
34+
import empathy_os.workflows.progressive.core # noqa: F401
35+
import empathy_os.workflows.progressive.orchestrator # noqa: F401
36+
import empathy_os.workflows.progressive.test_gen # noqa: F401
37+
import empathy_os.workflows.progressive.reports_analytics # noqa: F401
38+
import empathy_os.workflows.progressive.cost_telemetry # noqa: F401
39+
except ImportError:
40+
pass # Package might not be available in minimal test environments
41+
1142
# Load test environment variables from .env.test
1243
try:
1344
from dotenv import load_dotenv

0 commit comments

Comments
 (0)