Skip to content

Commit 8c09d25

Browse files
committed
add typing and error message
1 parent d19e2f3 commit 8c09d25

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

python_files/unittestadapter/django_handler.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Copyright (c) Microsoft Corporation. All rights reserved.
22
# Licensed under the MIT License.
33

4+
from importlib.machinery import ModuleSpec
45
import importlib.util
56
import os
67
import pathlib
@@ -89,7 +90,11 @@ def django_execution_runner(manage_py_path: str, test_ids: List[str], args: List
8990
sys.path.insert(0, os.fspath(django_project_dir))
9091
print(f"Django project directory: {django_project_dir}")
9192

92-
manage_spec = importlib.util.spec_from_file_location("manage", manage_py_path)
93+
manage_spec: ModuleSpec | None = importlib.util.spec_from_file_location(
94+
"manage", manage_py_path
95+
)
96+
if manage_spec is None or manage_spec.loader is None:
97+
raise VSCodeUnittestError("Error importing manage.py when running Django testing.")
9398
manage_module = importlib.util.module_from_spec(manage_spec)
9499
manage_spec.loader.exec_module(manage_module)
95100

0 commit comments

Comments
 (0)