diff options
-rw-r--r-- | pylint/lint/utils.py | 32 | ||||
-rw-r--r-- | tests/lint/test_utils.py | 12 |
2 files changed, 36 insertions, 8 deletions
diff --git a/pylint/lint/utils.py b/pylint/lint/utils.py index 8df7a2ef8..93ab8dfab 100644 --- a/pylint/lint/utils.py +++ b/pylint/lint/utils.py @@ -5,13 +5,14 @@ from __future__ import annotations import contextlib +import platform import sys import traceback from collections.abc import Iterator, Sequence from datetime import datetime from pathlib import Path -from pylint.constants import PYLINT_HOME +from pylint.constants import PYLINT_HOME, full_version def prepare_crash_report(ex: Exception, filepath: str, crash_file_path: str) -> Path: @@ -26,8 +27,9 @@ def prepare_crash_report(ex: Exception, filepath: str, crash_file_path: str) -> First, please verify that the bug is not already filled: https://github.com/PyCQA/pylint/issues/ -Then create a new crash issue: -https://github.com/PyCQA/pylint/issues/new?assignees=&labels=crash%2Cneeds+triage&template=BUG-REPORT.yml +Then create a new issue: +https://github.com/PyCQA/pylint/issues/new?labels=Crash 💥%2CNeeds triage 📥 + """ template += f""" @@ -63,10 +65,32 @@ pylint a.py ```python """ template += traceback.format_exc() - template += """ + template += f""" ``` + </details> + +### Expected behavior + +No crash. + +### Pylint version + +```shell +{full_version} +``` + +### OS / Environment + +{sys.platform} ({platform.system()}) + +### Additional dependencies + +<!-- +Please remove this part if you're not using any of +your dependencies in the example. + --> """ try: with open(issue_template_path, "a", encoding="utf8") as f: diff --git a/tests/lint/test_utils.py b/tests/lint/test_utils.py index 872919f72..682a65fdd 100644 --- a/tests/lint/test_utils.py +++ b/tests/lint/test_utils.py @@ -7,6 +7,7 @@ from pathlib import Path, PosixPath import pytest +from pylint.constants import full_version from pylint.lint.utils import get_fatal_error_message, prepare_crash_report from pylint.testutils._run import _Run as Run @@ -17,19 +18,22 @@ def test_prepare_crash_report(tmp_path: PosixPath) -> None: python_content = "from shadok import MagicFaucet" with open(python_file, "w", encoding="utf8") as f: f.write(python_content) + template_path = None try: - raise Exception(exception_content) # pylint: disable=broad-exception-raised - except Exception as ex: # pylint: disable=broad-except + raise ValueError(exception_content) + except ValueError as ex: template_path = prepare_crash_report( ex, str(python_file), str(tmp_path / "pylint-crash-%Y.txt") ) - assert str(tmp_path) in str(template_path) # pylint: disable=used-before-assignment + assert str(tmp_path) in str(template_path) with open(template_path, encoding="utf8") as f: template_content = f.read() assert python_content in template_content assert exception_content in template_content assert "in test_prepare_crash_report" in template_content - assert "raise Exception(exception_content)" in template_content + assert "raise ValueError(exception_content)" in template_content + assert "<details open>" in template_content + assert full_version in template_content def test_get_fatal_error_message() -> None: |