Skip to content

Commit

Permalink
Adding a more comprehensive printing in pytest (#2920)
Browse files Browse the repository at this point in the history
  • Loading branch information
germa89 authored Mar 21, 2024
1 parent 2780f04 commit 3f16bf6
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def has_grpc():


def has_dpf():
return os.environ.get("DPF_PORT", "")
return bool(os.environ.get("DPF_PORT", ""))


def is_smp():
Expand Down
33 changes: 33 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from collections import namedtuple
import os
from pathlib import Path
from shutil import get_terminal_size
from sys import platform

from _pytest.terminal import TerminalReporter # for terminal customization
Expand Down Expand Up @@ -238,6 +239,38 @@ def requires_dependency(dependency: str):
raise MapdlRuntimeError(ERRMSG)


@pytest.hookimpl(trylast=True)
def pytest_report_header(config, start_path, startdir):
text = []
text += ["Testing variables".center(get_terminal_size()[0], "-")]
text += [
f"Session dependent: ON_CI ({ON_CI}), TESTING_MINIMAL ({TESTING_MINIMAL}), SUPPORT_PLOTTING ({SUPPORT_PLOTTING})"
]
text += [
f"OS dependent: ON_LINUX ({ON_LINUX}), ON_UBUNTU ({ON_UBUNTU}), ON_WINDOWS ({ON_WINDOWS}), ON_MACOS )({ON_MACOS})"
]
text += [
f"MAPDL dependent: ON_LOCAL ({ON_LOCAL}), ON_STUDENT ({ON_STUDENT}), HAS_GRPC ({HAS_GRPC}), HAS_DPF ({HAS_DPF}), IS_SMP ({IS_SMP})"
]

text += ["Environment variables".center(get_terminal_size()[0], "-")]
line = ""
for env_var in [
"PYMAPDL_START_INSTANCE",
"PYMAPDL_PORT",
"PYMAPDL_DB_PORT",
"PYMAPDL_IP",
"DPF_PORT",
"DPF_START_SERVER",
]:
env_var_value = os.environ.get(env_var, None)
if env_var_value is not None:
line += f"{env_var} ('{env_var_value}'), "
text += [line]
text += ["Pytest configuration".center(get_terminal_size()[0], "-")]
return "\n".join(text)


## Changing report line length
class MyReporter(TerminalReporter):
def short_test_summary(self):
Expand Down

0 comments on commit 3f16bf6

Please sign in to comment.