Skip to content
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

feat: activate debug mode on testing using PYMAPDL_DEBUG_TESTING envvar #3594

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .ci/collect_mapdl_log_locals.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

mkdir "$LOG_NAMES" && echo "Successfully generated directory $LOG_NAMES"

cp *.log ./"$LOG_NAMES"/ || echo "No log files could be found"

ls -la ./"$LOG_NAMES"
10 changes: 10 additions & 0 deletions .ci/display_logs_locals.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Displaying files
FILE_PAT=./"$LOG_NAMES"/pymapdl.apdl
FILE_DESCRIPTION="PyMAPDL APDL log"

if compgen -G "$FILE_PAT" > /dev/null ;then for f in "$FILE_PAT"; do echo "::group:: $FILE_DESCRIPTION: $f" && cat "$f" && echo "::endgroup::" ; done; fi || echo "Failed to show $FILE_DESCRIPTION file"

FILE_PAT=./"$LOG_NAMES"/pymapdl.log
FILE_DESCRIPTION="PyMAPDL log"

if compgen -G "$FILE_PAT" > /dev/null ;then for f in "$FILE_PAT"; do echo "::group:: $FILE_DESCRIPTION: $f" && cat "$f" && echo "::endgroup::" ; done; fi || echo "Failed to show $FILE_DESCRIPTION file"
43 changes: 43 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ env:
PYTEST_ARGUMENTS: '-vvv -rxXsa --color=yes --durations=10 --random-order --random-order-bucket=class --maxfail=10 --reruns 3 --reruns-delay 4 --cov=ansys.mapdl.core --cov-report=html'

BUILD_CHEATSHEET: True
PYMAPDL_DEBUG_TESTING: True

# Following env vars when changed will "reset" the mentioned cache,
# by changing the cache file name. It is rendered as ...-v%RESET_XXX%-...
Expand Down Expand Up @@ -713,6 +714,27 @@ jobs:
--reset_only_failed --add_missing_images \
--cov-report=xml:${{ matrix.mapdl-version }}-local.xml

- name: "Collect logs on failure"
if: always()
env:
LOG_NAMES: logs-local-${{ matrix.mapdl-version }}
run: |
.ci/collect_mapdl_logs_local.sh

- name: "Upload logs to GitHub"
if: always()
uses: actions/upload-artifact@master
with:
name: logs-local-${{ matrix.mapdl-version }}.tgz
path: ./logs-local-${{ matrix.mapdl-version }}.tgz

- name: "Display files structure"
if: always()
env:
LOG_NAMES: logs-local-${{ matrix.mapdl-version }}
run: |
.ci/display_logs_locals.sh

- name: "Adding the directory as safe directory for later step"
run: |
git config --global --add safe.directory $GITHUB_WORKSPACE
Expand Down Expand Up @@ -850,6 +872,27 @@ jobs:
${{ env.PYTEST_ARGUMENTS }} \
--cov-report=xml:${{ matrix.mapdl-version }}-minimal.xml

- name: "Collect logs on failure"
if: always()
env:
LOG_NAMES: logs-minimal-${{ matrix.mapdl-version }}
run: |
.ci/collect_mapdl_logs_local.sh

- name: "Upload logs to GitHub"
if: always()
uses: actions/upload-artifact@master
with:
name: logs-minimal-${{ matrix.mapdl-version }}.tgz
path: ./logs-minimal-${{ matrix.mapdl-version }}.tgz

- name: "Display files structure"
if: always()
env:
LOG_NAMES: logs-minimal-${{ matrix.mapdl-version }}
run: |
.ci/display_logs_locals.sh

- uses: codecov/codecov-action@v5
name: "Upload coverage to Codecov"
with:
Expand Down
1 change: 1 addition & 0 deletions doc/changelog.d/3594.maintenance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
feat: debug testing
9 changes: 3 additions & 6 deletions src/ansys/mapdl/core/mapdl_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2216,6 +2216,8 @@ def run(

command = command.strip()

is_comment = command.startswith("!") or command.upper().startswith("/COM")

# always reset the cache
self._reset_cache()

Expand Down Expand Up @@ -2261,7 +2263,7 @@ def run(
# simply return the contents of the file
return self.list(*command.split(",")[1:])

if "=" in command:
if "=" in command and not is_comment:
# We are storing a parameter.
param_name = command.split("=")[0].strip()

Expand Down Expand Up @@ -2873,11 +2875,6 @@ def _raise_output_errors(self, response):
[each for each in error_message.splitlines() if each]
)

# Trimming empty lines
error_message = "\n".join(
[each for each in error_message.splitlines() if each]
)

# Checking for permitted error.
for each_error in _PERMITTED_ERRORS:
permited_error_message = re.search(each_error, error_message)
Expand Down
15 changes: 8 additions & 7 deletions tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,14 @@ def testing_minimal():
return os.environ.get("TESTING_MINIMAL", "NO").upper().strip() in ["YES", "TRUE"]


def log_apdl() -> bool:
if os.environ.get("PYMAPDL_LOG_APDL"):
log_apdl = os.environ.get("PYMAPDL_LOG_APDL")
def debug_testing() -> bool:
if os.environ.get("PYMAPDL_DEBUG_TESTING"):
debug_testing = os.environ.get("PYMAPDL_DEBUG_TESTING")

if log_apdl.lower() in ["true", "false", "yes", "no"]:
return log_apdl.lower() in ["true", "yes"]
if debug_testing.lower() in ["true", "false", "yes", "no"]:
return debug_testing.lower() in ["true", "yes"]
else:
return log_apdl
return debug_testing

else:
return False
Expand Down Expand Up @@ -228,7 +228,7 @@ def log_test_start(mapdl: Mapdl) -> None:
)

mapdl.run("!")
mapdl.run(f"! PyMAPDL running test: {test_name}")
mapdl.run(f"! PyMAPDL running test: {test_name}"[:639])
mapdl.run("!")

# To see it also in MAPDL terminal output
Expand All @@ -241,6 +241,7 @@ def log_test_start(mapdl: Mapdl) -> None:
types_ = ["File path", "Test function"]

mapdl._run("/com,Running test in:", mute=True)

for type_, name_ in zip(types_, test_name):
mapdl._run(f"/com, {type_}: {name_}", mute=True)

Expand Down
26 changes: 20 additions & 6 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
from common import (
Element,
Node,
debug_testing,
get_details_of_elements,
get_details_of_nodes,
has_dpf,
Expand All @@ -44,7 +45,6 @@
is_on_ubuntu,
is_running_on_student,
is_smp,
log_apdl,
log_test_start,
make_sure_not_instances_are_left_open,
restart_mapdl,
Expand All @@ -58,6 +58,7 @@
# ---------------------------
#

DEBUG_TESTING = debug_testing()
TESTING_MINIMAL = testing_minimal()

ON_LOCAL = is_on_local()
Expand All @@ -74,7 +75,6 @@
HAS_DPF = has_dpf()
SUPPORT_PLOTTING = support_plotting()
IS_SMP = is_smp()
LOG_APDL = log_apdl()

QUICK_LAUNCH_SWITCHES = "-smp -m 100 -db 100"
VALID_PORTS = []
Expand Down Expand Up @@ -183,6 +183,13 @@ def requires_dependency(dependency: str):
return pytest.mark.skip(reason=f"Requires '{dependency}' package")


if DEBUG_TESTING:
from ansys.mapdl.core import LOG

LOG.setLevel("DEBUG")
LOG.log_to_file("pymapdl.log")


germa89 marked this conversation as resolved.
Show resolved Hide resolved
################################################################
#
# Importing packages
Expand Down Expand Up @@ -265,7 +272,7 @@ 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})"
f"Session dependent: DEBUG_TESTING ({DEBUG_TESTING}), 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})"
Expand Down Expand Up @@ -429,7 +436,7 @@ def run_before_and_after_tests(
mapdl = restart_mapdl(mapdl)

# Write test info to log_apdl
if LOG_APDL:
if DEBUG_TESTING:
log_test_start(mapdl)

# check if the local/remote state has changed or not
Expand Down Expand Up @@ -551,7 +558,9 @@ def mapdl_console(request):
"Valid versions are up to 2020R2."
)

mapdl = launch_mapdl(console_path, log_apdl=LOG_APDL)
mapdl = launch_mapdl(
console_path, log_apdl="pymapdl.apdl" if DEBUG_TESTING else None
)
from ansys.mapdl.core.mapdl_console import MapdlConsole

assert isinstance(mapdl, MapdlConsole)
Expand Down Expand Up @@ -582,8 +591,10 @@ def mapdl(request, tmpdir_factory):
cleanup_on_exit=cleanup,
license_server_check=False,
start_timeout=50,
log_apdl=LOG_APDL,
log_apdl="pymapdl.apdl" if DEBUG_TESTING else None,
loglevel="DEBUG" if DEBUG_TESTING else "ERROR",
)

mapdl._show_matplotlib_figures = False # CI: don't show matplotlib figures
MAPDL_VERSION = mapdl.version # Caching version

Expand All @@ -595,6 +606,9 @@ def mapdl(request, tmpdir_factory):
if mapdl.is_local:
assert Path(mapdl.directory) == Path(run_path)

if DEBUG_TESTING:
mapdl._ctrl("set_verb", 5) # Setting verbosity on the server

germa89 marked this conversation as resolved.
Show resolved Hide resolved
# using yield rather than return here to be able to test exit
yield mapdl

Expand Down
Loading