Skip to content

Commit 95b6425

Browse files
committed
add typing and error message
1 parent d19e2f3 commit 95b6425

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

python_files/unittestadapter/django_handler.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@
77
import subprocess
88
import sys
99
from contextlib import contextmanager, suppress
10-
from typing import Generator, List
10+
from typing import TYPE_CHECKING, Generator, List
11+
12+
if TYPE_CHECKING:
13+
from importlib.machinery import ModuleSpec
14+
1115

1216
script_dir = pathlib.Path(__file__).parent
1317
sys.path.append(os.fspath(script_dir))
@@ -89,7 +93,11 @@ def django_execution_runner(manage_py_path: str, test_ids: List[str], args: List
8993
sys.path.insert(0, os.fspath(django_project_dir))
9094
print(f"Django project directory: {django_project_dir}")
9195

92-
manage_spec = importlib.util.spec_from_file_location("manage", manage_py_path)
96+
manage_spec: ModuleSpec | None = importlib.util.spec_from_file_location(
97+
"manage", manage_py_path
98+
)
99+
if manage_spec is None or manage_spec.loader is None:
100+
raise VSCodeUnittestError("Error importing manage.py when running Django testing.")
93101
manage_module = importlib.util.module_from_spec(manage_spec)
94102
manage_spec.loader.exec_module(manage_module)
95103

0 commit comments

Comments
 (0)