Skip to content

Commit 121c3d0

Browse files
feat: debug testing (#3594)
* feat: using an envvar to activate testing debugging * chore: adding changelog file 3594.maintenance.md [dependabot-skip] * fix: test logging name too long * fix: detecting comments as parameters sets when they have =. * fix: apply suggestions from code review * fix: script path name * fix: test * ci: using an external file for minimal requirements * fix: tests * refactor: moving dependency to requirement file * ci: fix files names. * fix: test * ci: adding logs to console --------- Co-authored-by: pyansys-ci-bot <[email protected]>
1 parent 59051c5 commit 121c3d0

File tree

11 files changed

+155
-21
lines changed

11 files changed

+155
-21
lines changed

.ci/collect_mapdl_logs_locals.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
mkdir "$LOG_NAMES" && echo "Successfully generated directory $LOG_NAMES"
3+
4+
cp *.log ./"$LOG_NAMES"/ || echo "No log files could be found"
5+
cp *apdl.out ./"$LOG_NAMES"/ || echo "No APDL log files could be found"
6+
cp *pymapdl.apdl ./"$LOG_NAMES"/ || echo "No PYMAPDL APDL log files could be found"
7+
8+
9+
ls -la ./"$LOG_NAMES"
10+
11+
echo "Tar files..."
12+
tar cvzf ./"$LOG_NAMES".tgz ./"$LOG_NAMES" || echo "Failed to compress"
File renamed without changes.

.ci/display_logs_locals.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
#####
3+
# Displaying files
4+
FILE_PAT=./"$LOG_NAMES"/pymapdl.log
5+
FILE_DESCRIPTION="PyMAPDL log"
6+
7+
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"
8+
9+
#####
10+
FILE_PAT=./"$LOG_NAMES"/pymapdl.apdl
11+
FILE_DESCRIPTION="PyMAPDL APDL log"
12+
13+
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"
14+
15+
#####
16+
FILE_PAT=./"$LOG_NAMES"/apdl.out
17+
FILE_DESCRIPTION="MAPDL Output"
18+
19+
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 renamed without changes.

.ci/requirements_minimal.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
pyfakefs==5.7.2
2+
pytest-cov==6.0.0
3+
pytest-random-order==1.1.1
4+
pytest-rerunfailures==15.0
5+
pytest-timeout==2.3.1
6+
pytest==8.3.4

.github/workflows/ci.yml

Lines changed: 70 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ env:
3636
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 --timeout=40'
3737

3838
BUILD_CHEATSHEET: True
39+
PYMAPDL_DEBUG_TESTING: True
3940

4041
# Following env vars when changed will "reset" the mentioned cache,
4142
# by changing the cache file name. It is rendered as ...-v%RESET_XXX%-...
@@ -337,7 +338,7 @@ jobs:
337338
MAPDL_INSTANCE: MAPDL_0
338339
LOG_NAMES: logs-build-docs
339340
run: |
340-
.ci/collect_mapdl_logs.sh
341+
.ci/collect_mapdl_logs_remote.sh
341342
342343
- name: "Upload logs to GitHub"
343344
if: always()
@@ -352,7 +353,7 @@ jobs:
352353
MAPDL_INSTANCE: MAPDL_0
353354
LOG_NAMES: logs-build-docs
354355
run: |
355-
.ci/display_logs.sh
356+
.ci/display_logs_remote.sh
356357
357358
build-test-remote-matrix:
358359
name: "Build remote test matrix"
@@ -577,7 +578,7 @@ jobs:
577578
MAPDL_INSTANCE: MAPDL_0
578579
LOG_NAMES: logs-remote-${{ matrix.mapdl-version }}
579580
run: |
580-
.ci/collect_mapdl_logs.sh
581+
.ci/collect_mapdl_logs_remote.sh
581582
582583
- name: "Upload logs to GitHub"
583584
if: always()
@@ -592,7 +593,7 @@ jobs:
592593
MAPDL_INSTANCE: MAPDL_0
593594
LOG_NAMES: logs-remote-${{ matrix.mapdl-version }}
594595
run: |
595-
.ci/display_logs.sh
596+
.ci/display_logs_remote.sh
596597
597598
build-test-local-minimal-matrix:
598599
name: "Build test matrix for minimal and local"
@@ -714,6 +715,27 @@ jobs:
714715
--reset_only_failed --add_missing_images \
715716
--cov-report=xml:${{ matrix.mapdl-version }}-local.xml
716717
718+
- name: "Collect logs on failure"
719+
if: always()
720+
env:
721+
LOG_NAMES: logs-local-${{ matrix.mapdl-version }}
722+
run: |
723+
.ci/collect_mapdl_logs_locals.sh
724+
725+
- name: "Upload logs to GitHub"
726+
if: always()
727+
uses: actions/upload-artifact@master
728+
with:
729+
name: logs-local-${{ matrix.mapdl-version }}.tgz
730+
path: ./logs-local-${{ matrix.mapdl-version }}.tgz
731+
732+
- name: "Display files structure"
733+
if: always()
734+
env:
735+
LOG_NAMES: logs-local-${{ matrix.mapdl-version }}
736+
run: |
737+
.ci/display_logs_locals.sh
738+
717739
- name: "Adding the directory as safe directory for later step"
718740
run: |
719741
git config --global --add safe.directory $GITHUB_WORKSPACE
@@ -822,7 +844,7 @@ jobs:
822844
823845
- name: "Unit testing requirements installation"
824846
run: |
825-
python -m pip install pytest pytest-rerunfailures pytest-cov pytest-random-order pyfakefs pytest-timeout
847+
python -m pip install -r .ci/requirements_minimal.txt
826848
827849
- name: "Unit testing"
828850
env:
@@ -851,6 +873,27 @@ jobs:
851873
${{ env.PYTEST_ARGUMENTS }} \
852874
--cov-report=xml:${{ matrix.mapdl-version }}-minimal.xml
853875
876+
- name: "Collect logs on failure"
877+
if: always()
878+
env:
879+
LOG_NAMES: logs-minimal-${{ matrix.mapdl-version }}
880+
run: |
881+
.ci/collect_mapdl_logs_locals.sh
882+
883+
- name: "Upload logs to GitHub"
884+
if: always()
885+
uses: actions/upload-artifact@master
886+
with:
887+
name: logs-minimal-${{ matrix.mapdl-version }}.tgz
888+
path: ./logs-minimal-${{ matrix.mapdl-version }}.tgz
889+
890+
- name: "Display files structure"
891+
if: always()
892+
env:
893+
LOG_NAMES: logs-minimal-${{ matrix.mapdl-version }}
894+
run: |
895+
.ci/display_logs_locals.sh
896+
854897
- uses: codecov/codecov-action@v5
855898
name: "Upload coverage to Codecov"
856899
with:
@@ -930,7 +973,7 @@ jobs:
930973
931974
- name: "Unit testing requirements installation"
932975
run: |
933-
python -m pip install pytest pytest-rerunfailures pytest-cov pytest-random-order pyfakefs pytest-timeout
976+
python -m pip install -r .ci/requirements_minimal.txt
934977
935978
- name: "Unit testing"
936979
env:
@@ -959,6 +1002,27 @@ jobs:
9591002
${{ env.PYTEST_ARGUMENTS }} \
9601003
--cov-report=xml:${{ matrix.mapdl-version }}-minimal-console.xml
9611004
1005+
- name: "Collect logs on failure"
1006+
if: always()
1007+
env:
1008+
LOG_NAMES: logs-minimal-console-${{ matrix.mapdl-version }}
1009+
run: |
1010+
.ci/collect_mapdl_logs_locals.sh
1011+
1012+
- name: "Upload logs to GitHub"
1013+
if: always()
1014+
uses: actions/upload-artifact@master
1015+
with:
1016+
name: logs-minimal-console-${{ matrix.mapdl-version }}.tgz
1017+
path: ./logs-minimal-console-${{ matrix.mapdl-version }}.tgz
1018+
1019+
- name: "Display files structure"
1020+
if: always()
1021+
env:
1022+
LOG_NAMES: logs-minimal-console-${{ matrix.mapdl-version }}
1023+
run: |
1024+
.ci/display_logs_locals.sh
1025+
9621026
- uses: codecov/codecov-action@v5
9631027
name: "Upload coverage to Codecov"
9641028
with:

doc/changelog.d/3594.maintenance.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
feat: activate debug mode on testing using `PYMAPDL_DEBUG_TESTING` envvar

tests/common.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -157,14 +157,14 @@ def testing_minimal():
157157
return os.environ.get("TESTING_MINIMAL", "NO").upper().strip() in ["YES", "TRUE"]
158158

159159

160-
def log_apdl() -> bool:
161-
if os.environ.get("PYMAPDL_LOG_APDL"):
162-
log_apdl = os.environ.get("PYMAPDL_LOG_APDL")
160+
def debug_testing() -> bool:
161+
if os.environ.get("PYMAPDL_DEBUG_TESTING"):
162+
debug_testing = os.environ.get("PYMAPDL_DEBUG_TESTING")
163163

164-
if log_apdl.lower() in ["true", "false", "yes", "no"]:
165-
return log_apdl.lower() in ["true", "yes"]
164+
if debug_testing.lower() in ["true", "false", "yes", "no"]:
165+
return debug_testing.lower() in ["true", "yes"]
166166
else:
167-
return log_apdl
167+
return debug_testing
168168

169169
else:
170170
return False
@@ -228,7 +228,7 @@ def log_test_start(mapdl: Mapdl) -> None:
228228
)
229229

230230
mapdl.run("!")
231-
mapdl.run(f"! PyMAPDL running test: {test_name}")
231+
mapdl.run(f"! PyMAPDL running test: {test_name}"[:639])
232232
mapdl.run("!")
233233

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

243243
mapdl._run("/com,Running test in:", mute=True)
244+
244245
for type_, name_ in zip(types_, test_name):
245246
mapdl._run(f"/com, {type_}: {name_}", mute=True)
246247

tests/conftest.py

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
from common import (
3636
Element,
3737
Node,
38+
debug_testing,
3839
get_details_of_elements,
3940
get_details_of_nodes,
4041
has_dpf,
@@ -44,7 +45,6 @@
4445
is_on_ubuntu,
4546
is_running_on_student,
4647
is_smp,
47-
log_apdl,
4848
log_test_start,
4949
make_sure_not_instances_are_left_open,
5050
restart_mapdl,
@@ -58,6 +58,7 @@
5858
# ---------------------------
5959
#
6060

61+
DEBUG_TESTING = debug_testing()
6162
TESTING_MINIMAL = testing_minimal()
6263

6364
ON_LOCAL = is_on_local()
@@ -74,7 +75,6 @@
7475
HAS_DPF = has_dpf()
7576
SUPPORT_PLOTTING = support_plotting()
7677
IS_SMP = is_smp()
77-
LOG_APDL = log_apdl()
7878

7979
QUICK_LAUNCH_SWITCHES = "-smp -m 100 -db 100"
8080
VALID_PORTS = []
@@ -183,6 +183,17 @@ def requires_dependency(dependency: str):
183183
return pytest.mark.skip(reason=f"Requires '{dependency}' package")
184184

185185

186+
if DEBUG_TESTING:
187+
from ansys.mapdl.core import LOG
188+
189+
LOG.setLevel("DEBUG")
190+
191+
# If the following file name is changed, update `ci.yml`.
192+
LOG.log_to_file("pymapdl.log")
193+
194+
# the following files are also generated by MAPDL gRPC:
195+
# - "pymapdl.apdl": The APDL commands sent to MAPDL by PyMAPDL
196+
# - "apdl.out" : MAPDL console output. Very likely only contains the output until connected.
186197
################################################################
187198
#
188199
# Importing packages
@@ -265,7 +276,7 @@ def pytest_report_header(config, start_path, startdir):
265276
text = []
266277
text += ["Testing variables".center(get_terminal_size()[0], "-")]
267278
text += [
268-
f"Session dependent: ON_CI ({ON_CI}), TESTING_MINIMAL ({TESTING_MINIMAL}), SUPPORT_PLOTTING ({SUPPORT_PLOTTING})"
279+
f"Session dependent: DEBUG_TESTING ({DEBUG_TESTING}), ON_CI ({ON_CI}), TESTING_MINIMAL ({TESTING_MINIMAL}), SUPPORT_PLOTTING ({SUPPORT_PLOTTING})"
269280
]
270281
text += [
271282
f"OS dependent: ON_LINUX ({ON_LINUX}), ON_UBUNTU ({ON_UBUNTU}), ON_WINDOWS ({ON_WINDOWS}), ON_MACOS ({ON_MACOS})"
@@ -429,7 +440,7 @@ def run_before_and_after_tests(
429440
mapdl = restart_mapdl(mapdl)
430441

431442
# Write test info to log_apdl
432-
if LOG_APDL:
443+
if DEBUG_TESTING:
433444
log_test_start(mapdl)
434445

435446
# check if the local/remote state has changed or not
@@ -546,7 +557,9 @@ def mapdl_console(request):
546557
"Valid versions are up to 2020R2."
547558
)
548559

549-
mapdl = launch_mapdl(console_path, mode="console", log_apdl=LOG_APDL)
560+
mapdl = launch_mapdl(
561+
console_path, mode="console", log_apdl="pymapdl.apdl" if DEBUG_TESTING else None
562+
)
550563
from ansys.mapdl.core.mapdl_console import MapdlConsole
551564

552565
assert isinstance(mapdl, MapdlConsole)
@@ -577,8 +590,12 @@ def mapdl(request, tmpdir_factory):
577590
cleanup_on_exit=cleanup,
578591
license_server_check=False,
579592
start_timeout=50,
580-
log_apdl=LOG_APDL,
593+
loglevel="DEBUG" if DEBUG_TESTING else "ERROR",
594+
# If the following file names are changed, update `ci.yml`.
595+
log_apdl="pymapdl.apdl" if DEBUG_TESTING else None,
596+
mapdl_output="apdl.out" if (DEBUG_TESTING and ON_LOCAL) else None,
581597
)
598+
582599
mapdl._show_matplotlib_figures = False # CI: don't show matplotlib figures
583600
MAPDL_VERSION = mapdl.version # Caching version
584601

tests/test_grpc.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -577,13 +577,19 @@ def test_input_compatibility_api_change(mapdl, cleared):
577577

578578
@requires("grpc")
579579
@requires("local")
580-
def test__check_stds(mapdl, cleared):
580+
@requires("nostudent")
581+
def test__check_stds():
581582
"""Test that the standard input is checked."""
583+
from ansys.mapdl.core import launch_mapdl
584+
585+
mapdl = launch_mapdl(port=50058)
582586

583587
mapdl._read_stds()
584588
assert mapdl._stdout is not None
585589
assert mapdl._stderr is not None
586590

591+
mapdl.exit(force=True)
592+
587593

588594
def test_subscribe_to_channel(mapdl, cleared):
589595
assert mapdl.channel_state in [

0 commit comments

Comments
 (0)