forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
implement django tests with custom runner #22222
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import subprocess | ||
import os | ||
import pathlib | ||
import sys | ||
from typing import Union | ||
|
||
from pythonFiles.unittestadapter.execution import VSCodeUnittestError | ||
|
||
|
||
def django_execution_runner(start_dir: Union[str, None]): | ||
# Get path to manage.py if set as an env var, otherwise use the default | ||
manage_py_path = os.environ.get("MANAGE_PY_PATH") | ||
|
||
if manage_py_path is None: | ||
# Search for default manage.py path at the root of the workspace | ||
if not start_dir: | ||
print( | ||
"Error running Django, no start_dir provided or value for MANAGE_PY_PATH" | ||
) | ||
|
||
cwd = os.path.abspath(start_dir) | ||
Check failure on line 21 in pythonFiles/unittestadapter/django_runner.py GitHub Actions / Check Python types
|
||
manage_py_path = os.path.join(cwd, "manage.py") | ||
|
||
try: | ||
# Get path to the custom_test_runner.py parent folder, add to sys.path. | ||
custom_test_runner_dir = pathlib.Path(__file__).parent | ||
sys.path.insert(0, custom_test_runner_dir) | ||
Check failure on line 27 in pythonFiles/unittestadapter/django_runner.py GitHub Actions / Check Python types
|
||
custom_test_runner = "django_test_runner.CustomTestRunner" | ||
|
||
# Build command to run 'python manage.py test'. | ||
python_executable = sys.executable | ||
command = [ | ||
python_executable, | ||
"manage.py", | ||
"test", | ||
"--testrunner", | ||
custom_test_runner, | ||
] | ||
print("Running Django run tests with command: ", command) | ||
try: | ||
subprocess.run(" ".join(command), shell=True, check=True) | ||
except subprocess.CalledProcessError as e: | ||
print(f"Error running 'manage.py test': {e}") | ||
raise VSCodeUnittestError(f"Error running 'manage.py test': {e}") | ||
except Exception as e: | ||
print(f"Error configuring Django test runner: {e}") | ||
raise VSCodeUnittestError(f"Error configuring Django test runner: {e}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from django.test.runner import DiscoverRunner | ||
import sys | ||
import os | ||
import pathlib | ||
|
||
script_dir = pathlib.Path(__file__).parent | ||
sys.path.append(os.fspath(script_dir)) | ||
|
||
from execution import UnittestTestResult | ||
|
||
|
||
class CustomTestRunner(DiscoverRunner): | ||
def get_test_runner_kwargs(self): | ||
print("get_test_runner_kwargs") | ||
kwargs = super().get_test_runner_kwargs() | ||
if kwargs["resultclass"] is not None: | ||
raise ValueError( | ||
"Resultclass already set, cannot use custom test runner design for VS Code compatibility." | ||
) | ||
kwargs["resultclass"] = UnittestTestResult | ||
return kwargs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a space as the join argument? I think I already put one in between the " but ill check