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

Merged
merged 21 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
e105729
feat: using an envvar to activate testing debugging
germa89 Nov 29, 2024
4d4d5df
chore: adding changelog file 3594.maintenance.md [dependabot-skip]
pyansys-ci-bot Nov 29, 2024
2072976
fix: test logging name too long
germa89 Nov 29, 2024
c69cd3e
fix: detecting comments as parameters sets when they have =.
germa89 Nov 27, 2024
805b853
fix: apply suggestions from code review
germa89 Dec 10, 2024
642bd37
Merge branch 'main' into feat/debugging-mode-in-cicd
germa89 Dec 10, 2024
0c3ff5b
Merge branch 'main' into feat/debugging-mode-in-cicd
germa89 Dec 13, 2024
15faad6
fix: script path name
germa89 Dec 13, 2024
7b896ac
Merge branch 'main' into feat/debugging-mode-in-cicd
germa89 Dec 13, 2024
25127f9
fix: test
germa89 Dec 13, 2024
c099080
Merge branch 'main' into feat/debugging-mode-in-cicd
germa89 Dec 13, 2024
6e61abc
ci: using an external file for minimal requirements
germa89 Dec 13, 2024
9f4d4c4
fix: tests
germa89 Dec 13, 2024
b494abf
Merge branch 'main' into feat/debugging-mode-in-cicd
germa89 Dec 13, 2024
fc4b549
refactor: moving dependency to requirement file
germa89 Dec 13, 2024
30b5514
ci: fix files names.
germa89 Dec 13, 2024
3d94ec4
fix: test
germa89 Dec 13, 2024
c513f14
ci: adding logs to console
germa89 Dec 13, 2024
6f7e0eb
Merge branch 'main' into feat/debugging-mode-in-cicd
germa89 Dec 13, 2024
104b988
chore: adding changelog file 3594.maintenance.md [dependabot-skip]
pyansys-ci-bot Dec 16, 2024
c1ce78a
Merge branch 'main' into feat/debugging-mode-in-cicd
germa89 Dec 18, 2024
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
12 changes: 12 additions & 0 deletions .ci/collect_mapdl_logs_locals.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

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

cp *.log ./"$LOG_NAMES"/ || echo "No log files could be found"
cp *apdl.out ./"$LOG_NAMES"/ || echo "No APDL log files could be found"
cp *pymapdl.apdl ./"$LOG_NAMES"/ || echo "No PYMAPDL APDL log files could be found"


ls -la ./"$LOG_NAMES"

echo "Tar files..."
tar cvzf ./"$LOG_NAMES".tgz ./"$LOG_NAMES" || echo "Failed to compress"
File renamed without changes.
19 changes: 19 additions & 0 deletions .ci/display_logs_locals.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

#####
# Displaying files
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"

#####
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"/apdl.out
FILE_DESCRIPTION="MAPDL Output"

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.
6 changes: 6 additions & 0 deletions .ci/requirements_minimal.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pyfakefs==5.7.2
pytest-cov==6.0.0
pytest-random-order==1.1.1
pytest-rerunfailures==15.0
pytest-timeout==2.3.1
pytest==8.3.4
76 changes: 70 additions & 6 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 --timeout=40'

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 @@ -337,7 +338,7 @@ jobs:
MAPDL_INSTANCE: MAPDL_0
LOG_NAMES: logs-build-docs
run: |
.ci/collect_mapdl_logs.sh
.ci/collect_mapdl_logs_remote.sh

- name: "Upload logs to GitHub"
if: always()
Expand All @@ -352,7 +353,7 @@ jobs:
MAPDL_INSTANCE: MAPDL_0
LOG_NAMES: logs-build-docs
run: |
.ci/display_logs.sh
.ci/display_logs_remote.sh

build-test-remote-matrix:
name: "Build remote test matrix"
Expand Down Expand Up @@ -577,7 +578,7 @@ jobs:
MAPDL_INSTANCE: MAPDL_0
LOG_NAMES: logs-remote-${{ matrix.mapdl-version }}
run: |
.ci/collect_mapdl_logs.sh
.ci/collect_mapdl_logs_remote.sh

- name: "Upload logs to GitHub"
if: always()
Expand All @@ -592,7 +593,7 @@ jobs:
MAPDL_INSTANCE: MAPDL_0
LOG_NAMES: logs-remote-${{ matrix.mapdl-version }}
run: |
.ci/display_logs.sh
.ci/display_logs_remote.sh

build-test-local-minimal-matrix:
name: "Build test matrix for minimal and local"
Expand Down Expand Up @@ -714,6 +715,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_locals.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 @@ -822,7 +844,7 @@ jobs:

- name: "Unit testing requirements installation"
run: |
python -m pip install pytest pytest-rerunfailures pytest-cov pytest-random-order pyfakefs pytest-timeout
python -m pip install -r .ci/requirements_minimal.txt

- name: "Unit testing"
env:
Expand Down Expand Up @@ -851,6 +873,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_locals.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 Expand Up @@ -930,7 +973,7 @@ jobs:

- name: "Unit testing requirements installation"
run: |
python -m pip install pytest pytest-rerunfailures pytest-cov pytest-random-order pyfakefs pytest-timeout
python -m pip install -r .ci/requirements_minimal.txt

- name: "Unit testing"
env:
Expand Down Expand Up @@ -959,6 +1002,27 @@ jobs:
${{ env.PYTEST_ARGUMENTS }} \
--cov-report=xml:${{ matrix.mapdl-version }}-minimal-console.xml

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

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

- name: "Display files structure"
if: always()
env:
LOG_NAMES: logs-minimal-console-${{ 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: activate debug mode on testing using `PYMAPDL_DEBUG_TESTING` envvar
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
29 changes: 23 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,17 @@ 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")

# If the following file name is changed, update `ci.yml`.
LOG.log_to_file("pymapdl.log")

# the following files are also generated by MAPDL gRPC:
# - "pymapdl.apdl": The APDL commands sent to MAPDL by PyMAPDL
# - "apdl.out" : MAPDL console output. Very likely only contains the output until connected.
################################################################
#
# Importing packages
Expand Down Expand Up @@ -265,7 +276,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 +440,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 @@ -546,7 +557,9 @@ def mapdl_console(request):
"Valid versions are up to 2020R2."
)

mapdl = launch_mapdl(console_path, mode="console", log_apdl=LOG_APDL)
mapdl = launch_mapdl(
console_path, mode="console", 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 @@ -577,8 +590,12 @@ def mapdl(request, tmpdir_factory):
cleanup_on_exit=cleanup,
license_server_check=False,
start_timeout=50,
log_apdl=LOG_APDL,
loglevel="DEBUG" if DEBUG_TESTING else "ERROR",
# If the following file names are changed, update `ci.yml`.
log_apdl="pymapdl.apdl" if DEBUG_TESTING else None,
mapdl_output="apdl.out" if (DEBUG_TESTING and ON_LOCAL) else None,
)

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

Expand Down
8 changes: 7 additions & 1 deletion tests/test_grpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -577,13 +577,19 @@ def test_input_compatibility_api_change(mapdl, cleared):

@requires("grpc")
@requires("local")
def test__check_stds(mapdl, cleared):
@requires("nostudent")
def test__check_stds():
"""Test that the standard input is checked."""
from ansys.mapdl.core import launch_mapdl

mapdl = launch_mapdl(port=50058)

mapdl._read_stds()
assert mapdl._stdout is not None
assert mapdl._stderr is not None

mapdl.exit(force=True)


def test_subscribe_to_channel(mapdl, cleared):
assert mapdl.channel_state in [
Expand Down
10 changes: 9 additions & 1 deletion tests/test_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,12 @@ def test_log_to_file(tmpdir):
LOG.logger.setLevel("ERROR")
LOG.std_out_handler.setLevel("ERROR")

if not LOG.file_handler:
if LOG.file_handler is None:
old_logger = None
LOG.log_to_file(file_path)
else:
# the logger has been already instantiated
old_logger = LOG.file_handler.baseFilename
LOG.log_to_file(file_path)

LOG.error(file_msg_error)
Expand All @@ -313,6 +318,9 @@ def test_log_to_file(tmpdir):

assert file_msg_debug in text

if old_logger is not None:
LOG.log_to_file(old_logger)


def test_log_instance_name(mapdl, cleared):
# verify we can access via an instance name
Expand Down
Loading