Skip to content

Commit 9e58b8e

Browse files
committed
Fix import errors in test files
- Fix relative import issues by using absolute path calculations - Properly add both project root and tests directory to sys.path - This resolves 'ImportError: attempted relative import with no known parent package' errors
1 parent b3d6de3 commit 9e58b8e

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

tests/performance/test_performance.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88

99

1010
# Add parent directory to path for imports
11-
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
12-
13-
from ..test_utils import get_safe_timezone
11+
project_root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
12+
tests_dir = os.path.join(project_root, 'tests')
13+
sys.path.insert(0, project_root) # For pythonLogs
14+
sys.path.insert(0, tests_dir) # For test_utils in tests/
15+
from test_utils import get_safe_timezone
1416

1517
from pythonLogs import (
1618
LoggerFactory,

tests/timezone/test_timezone_migration.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@
77

88

99
# Add parent directory to path for imports
10-
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
11-
12-
from ..test_utils import skip_if_no_zoneinfo_utc, get_safe_timezone, requires_zoneinfo_utc
10+
project_root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
11+
tests_dir = os.path.join(project_root, 'tests')
12+
sys.path.insert(0, project_root) # For pythonLogs
13+
sys.path.insert(0, tests_dir) # For test_utils in tests/
14+
from test_utils import skip_if_no_zoneinfo_utc, get_safe_timezone, requires_zoneinfo_utc
1315

1416
from pythonLogs import (
1517
basic_logger,

tests/timezone/test_zoneinfo_fallbacks.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88

99

1010
# Add parent directory to path for imports
11-
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
12-
13-
from ..test_utils import skip_if_no_zoneinfo_utc, get_safe_timezone, requires_zoneinfo_utc
11+
project_root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
12+
tests_dir = os.path.join(project_root, 'tests')
13+
sys.path.insert(0, project_root) # For pythonLogs
14+
sys.path.insert(0, tests_dir) # For test_utils in tests/
15+
from test_utils import skip_if_no_zoneinfo_utc, get_safe_timezone, requires_zoneinfo_utc
1416

1517

1618
class TestZoneinfoFallbacks:

0 commit comments

Comments
 (0)