Skip to content

Commit c58d991

Browse files
authored
Update test_main.py
Reorder import. Load app from src/app.py. Add commented Alternative Method to Modify sys.path for importing app from main.py , non ideal, when tests rely on running the application entry point.
1 parent 2fbe4ec commit c58d991

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

tests/test_main.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,29 @@
1-
import unittest
21
import os
32
import json
3+
import unittest
44
from unittest.mock import patch
5+
56
from typer.testing import CliRunner
67

7-
from main import app
8+
# Import from the local package located in the 'src' directory
9+
from src.app import app
10+
11+
# Import the 'app' object from the local module in the 'src' package.
12+
from src.app import app
13+
14+
# --- Alternative Method to Modify sys.path for Testing ---
15+
# This approach is used to allow importing main.py, which is located in the project's root directory,
16+
# when such tests rely on running the application entry point.
17+
# Note: main.py defines a main() function and runs it if executed directly by the user.
18+
# Modifying sys.path is less ideal because it involves changing the import path at runtime, which can lead to
19+
# maintenance issues or conflicts with the module namespace.
20+
21+
# # Uncomment the line below to update sys.path, adding the project root directory.
22+
# import sys
23+
# sys.path.insert(0, os.path.abspath(
24+
# os.path.join(os.path.dirname(__file__), '..')
25+
# ))
26+
# from main import app
827

928
TEST_DRAFTS_FILE = "test-drafts.json"
1029

0 commit comments

Comments
 (0)