From 873c398d6deeafeb870ef7d7f569bb0103619a6d Mon Sep 17 00:00:00 2001 From: Eleanor Boyd Date: Wed, 4 Sep 2024 09:43:08 -0700 Subject: [PATCH] fix django manage.py path validation (#24019) (#24045) fixes https://github.com/microsoft/vscode-python/issues/24001, cherry pick into release --- python_files/unittestadapter/django_handler.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/python_files/unittestadapter/django_handler.py b/python_files/unittestadapter/django_handler.py index dc520c13aff1..9daa816d0918 100644 --- a/python_files/unittestadapter/django_handler.py +++ b/python_files/unittestadapter/django_handler.py @@ -18,10 +18,8 @@ def django_discovery_runner(manage_py_path: str, args: List[str]) -> None: # Attempt a small amount of validation on the manage.py path. - try: - pathlib.Path(manage_py_path) - except Exception as e: - raise VSCodeUnittestError(f"Error running Django, manage.py path is not a valid path: {e}") # noqa: B904 + if not pathlib.Path(manage_py_path).exists(): + raise VSCodeUnittestError("Error running Django, manage.py path does not exist.") try: # Get path to the custom_test_runner.py parent folder, add to sys.path and new environment used for subprocess. @@ -61,10 +59,8 @@ def django_discovery_runner(manage_py_path: str, args: List[str]) -> None: def django_execution_runner(manage_py_path: str, test_ids: List[str], args: List[str]) -> None: # Attempt a small amount of validation on the manage.py path. - try: - pathlib.Path(manage_py_path) - except Exception as e: - raise VSCodeUnittestError(f"Error running Django, manage.py path is not a valid path: {e}") # noqa: B904 + if not pathlib.Path(manage_py_path).exists(): + raise VSCodeUnittestError("Error running Django, manage.py path does not exist.") try: # Get path to the custom_test_runner.py parent folder, add to sys.path.