Last active
March 5, 2025 12:57
-
-
Save AlonsoMackenlly/3d51ae56ff07f474f7e91e8c7b7f09ee to your computer and use it in GitHub Desktop.
PyCharm pytest verbose of nodes names by docstring
This file contains hidden or 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
def pytest_itemcollected(item): | |
"""Модифицирует название теста при сборке.""" | |
if isinstance(item, pytest.Function): # Проверяем, что это тестовая функция | |
class_doc = item.parent.obj.__doc__.strip() if item.parent.obj.__doc__ else "" | |
method_doc = item.obj.__doc__.strip() if item.obj.__doc__ else "" | |
if class_doc and method_doc: | |
# Используем описание класса и метода | |
item._nodeid = f"{class_doc} | {item.parent.obj.__name__}::{method_doc}" | |
elif method_doc: | |
# Если только у метода есть описание | |
item._nodeid = method_doc | |
else: | |
# Если нет описания, оставляем стандартное имя | |
item._nodeid = item.nodeid |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment