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

refactor: testing suite (random order) #3519

Merged
merged 71 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
9b7588b
ci: using random order when doing the tests
germa89 Oct 25, 2024
6ea5713
ci: using random order when doing the tests
germa89 Oct 25, 2024
e206260
chore: adding changelog file 3519.dependencies.md [dependabot-skip]
pyansys-ci-bot Oct 25, 2024
0049ea1
Merge branch 'ci/doing-random-tests-on-ci' of https://github.com/ansy…
germa89 Oct 25, 2024
f76089a
test: to get more info
germa89 Oct 25, 2024
7ba5de2
fix: making sure we are plotting something
germa89 Nov 18, 2024
fe25624
chore: merge remote-tracking branch 'origin/main' into ci/doing-rando…
germa89 Nov 18, 2024
09074cf
feat: avoid mixing class tests
germa89 Nov 18, 2024
f21f6aa
feat: removing scoping to module only.
germa89 Nov 18, 2024
3482266
feat: testing resuming between class methods
germa89 Nov 18, 2024
5bfa745
test: fixing some tests
germa89 Nov 18, 2024
06fa1b9
fix: more tests
germa89 Nov 18, 2024
890cd83
fix: tests
germa89 Nov 18, 2024
bad6d06
fix: tests
germa89 Nov 18, 2024
0f4f4c9
fix: logging test
germa89 Nov 19, 2024
c2578d0
fix: pymapdl::tests::test_mapdl.py::test_equal_in_comments_and_title
germa89 Nov 19, 2024
4219d32
test: uncommenting test
germa89 Nov 19, 2024
5877612
feat: improving cleared fixture to clean format too. Using the fixtur…
germa89 Nov 19, 2024
af2de52
fix: double fixture
germa89 Nov 19, 2024
03c0251
fix: fixtures
germa89 Nov 19, 2024
0e7fa22
feat: making sure the MAPDL database is clean up on class Test creation.
germa89 Nov 19, 2024
8dc0d33
fix: get_port test
germa89 Nov 19, 2024
4726fd5
fix: using lower scope fixture on high scope fixture in database module
germa89 Nov 19, 2024
11016db
chore: adding test dependency in minimal
germa89 Nov 19, 2024
76a8e51
fix: missing staticmethods
germa89 Nov 19, 2024
d2067ca
fix: tests
germa89 Nov 19, 2024
94229a5
fix: tests
germa89 Nov 19, 2024
e738ac1
fix: logging test
germa89 Nov 19, 2024
2b56a70
test: check we are not changing state
germa89 Nov 19, 2024
0214ed5
chore: update the image cache
germa89 Nov 19, 2024
2f2410a
chore: empty commit to trigger CICD
germa89 Nov 19, 2024
d60ce35
fix: codecov issues
germa89 Nov 19, 2024
bfb8ec1
fix: test
germa89 Nov 19, 2024
db10bec
chore: merge remote-tracking branch 'origin/main' into ci/doing-rando…
germa89 Nov 19, 2024
f1d8937
fix: typos
germa89 Nov 20, 2024
99350dd
fix: update golden data
germa89 Nov 20, 2024
a7264c9
fix: not calling a method and reducing tolerance for matching.
germa89 Nov 20, 2024
b3f25d3
fix: setting graphics, full as default for testing
germa89 Nov 20, 2024
68524fe
refactor: test organization
germa89 Nov 20, 2024
9ab8af4
fix: test
germa89 Nov 20, 2024
ce26b31
chore: update the image cache
germa89 Nov 20, 2024
9cea45a
chore: empty comment to trigger CICD
germa89 Nov 20, 2024
9844cd4
chore: update the image cache
germa89 Nov 20, 2024
8188e98
chore: empty comment to trigger CICD
germa89 Nov 20, 2024
4ad512b
chore: update the image cache
germa89 Nov 20, 2024
7f6d673
fix: test_igesin_whitespace
germa89 Nov 21, 2024
aeba7c4
chore: update the image cache
germa89 Nov 21, 2024
974fee7
feat: clearing all tests before running.
germa89 Nov 21, 2024
fed1e29
Merge branch 'ci/doing-random-tests-on-ci' of https://github.com/ansy…
germa89 Nov 21, 2024
37657ad
chore: adding changelog file 3519.documentation.md [dependabot-skip]
pyansys-ci-bot Nov 21, 2024
1149ef3
chore: update the image cache
pyansys-ci-bot Nov 21, 2024
8fbad5a
fix: test
germa89 Nov 21, 2024
c80bca6
test: rebuilding the plotting config every time
germa89 Nov 21, 2024
8e4efa7
chore: update the image cache
germa89 Nov 21, 2024
26eccf2
fix: codecov issues
germa89 Nov 21, 2024
b8bf4af
Merge branch 'main' into ci/doing-random-tests-on-ci
germa89 Nov 21, 2024
2181960
ci: reducing the amount of version tested to only last 2.
germa89 Nov 21, 2024
c195be8
fix: adding missing import
germa89 Nov 21, 2024
1e245f7
feat: assert no changes on type of plotting
germa89 Nov 21, 2024
23ddab3
fix: method name
germa89 Nov 22, 2024
ea98895
chore: merge remote-tracking branch 'origin/main' into ci/doing-rando…
germa89 Nov 22, 2024
e1a8b34
fix: function replacement
germa89 Nov 22, 2024
fcff2fc
chore: merge remote-tracking branch 'origin/main' into ci/doing-rando…
germa89 Nov 22, 2024
7f3e704
feat: restoring default in test_command
germa89 Nov 22, 2024
7e51961
fix: test_freq
germa89 Nov 22, 2024
4c013e1
fix: removing duplicated function
germa89 Nov 22, 2024
600d907
fix: show issue
germa89 Nov 22, 2024
6b0ed52
test: remove mute
germa89 Nov 22, 2024
ecbeab8
chore: apply suggestions from code review
germa89 Nov 22, 2024
04539dd
ci: auto fixes from pre-commit.com hooks.
pre-commit-ci[bot] Nov 22, 2024
d3d50ef
chore: adding changelog file 3519.added.md [dependabot-skip]
pyansys-ci-bot Nov 22, 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
5 changes: 3 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ env:
DPF_PORT: 21004
MAPDL_PACKAGE: ghcr.io/ansys/mapdl
ON_CI: True
PYTEST_ARGUMENTS: '-vvv --color=yes -ra --durations=10 --maxfail=3 --reruns 3 --reruns-delay 4 --cov=ansys.mapdl.core --cov-report=html'
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

# Following env vars when changed will "reset" the mentioned cache,
Expand Down Expand Up @@ -820,7 +821,7 @@ jobs:

- name: "Unit testing requirements installation"
run: |
python -m pip install pytest pytest-rerunfailures pytest-cov
python -m pip install pytest pytest-rerunfailures pytest-cov pytest-random-order

- name: "Unit testing"
env:
Expand Down
1 change: 1 addition & 0 deletions doc/changelog.d/3519.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
refactor: testing suite (random order)
4 changes: 3 additions & 1 deletion doc/source/getting_started/develop_pymapdl.rst
Original file line number Diff line number Diff line change
Expand Up @@ -230,12 +230,14 @@ It is executed upstream of each test and not within all tests.

.. code:: python

def test_my_new_feature(mapdl): # pass the 'mapdl' fixture as an argument.
def test_my_new_feature(mapdl, cleared): # pass the 'mapdl' fixture as an argument.
mapdl.prep7()
# .... more code

return True # if everything goes ok until here

Passing the ``cleared`` fixture is also useful since it clears up the MAPDL database
and configuration before performing the test.
If you do not have MAPDL installed locally but still want to run the
unit testing, you must set up the following environment variables.

Expand Down
9 changes: 5 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ dependencies = [
"ansys-mapdl-reader>=0.51.7",
"ansys-math-core>=0.1.2",
"ansys-platform-instancemanagement~=1.0",
"ansys-tools-visualization-interface>=0.2.6",
"ansys-tools-path>=0.3.1",
"ansys-tools-visualization-interface>=0.2.6",
"click>=8.1.3", # for CLI interface
"grpcio>=1.30.0", # tested up to grpcio==1.35
"matplotlib>=3.0.0", # for colormaps for pyvista
Expand Down Expand Up @@ -67,6 +67,7 @@ tests = [
"pytest-cov==6.0.0",
"pytest-memprof<0.3.0",
"pytest-pyvista==0.1.9",
"pytest-random-order==1.1.1",
"pytest-rerunfailures==15.0",
"pytest==8.3.3",
"scipy==1.14.1",
Expand All @@ -75,13 +76,13 @@ tests = [
doc = [
"ansys-dpf-core==0.10.1",
"ansys-mapdl-reader==0.54.2",
"ansys-tools-visualization-interface==0.5.0",
"ansys-sphinx-theme==1.2.2",
"ansys-tools-visualization-interface==0.5.0",
"grpcio==1.68.0",
"imageio-ffmpeg==0.5.1",
"imageio==2.36.0",
"jupyter==1.1.1",
"jupyter_sphinx==0.5.3",
"jupyter==1.1.1",
"jupyterlab>=3.2.8",
"matplotlib==3.9.2",
"nbformat==5.10.4",
Expand Down Expand Up @@ -119,7 +120,7 @@ pymapdl_convert_script = "ansys.mapdl.core.cli:old_pymapdl_convert_script_entry_
pymapdl = "ansys.mapdl.core.cli:main"

[tool.pytest.ini_options]
addopts = "-rxXsa -vvv --maxfail=10"
addopts = "-rxXsa -vvv --maxfail=10 --random-order-bucket=class --random-order --durations=10"
junit_family = "legacy"
filterwarnings = [
"ignore::FutureWarning",
Expand Down
1 change: 1 addition & 0 deletions src/ansys/mapdl/core/mapdl_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1560,6 +1560,7 @@ def open_apdl_log(
"""
if self._apdl_log is not None:
raise MapdlRuntimeError("APDL command logging already enabled")

self._log.debug("Opening ANSYS log file at %s", filename)

if mode not in ["w", "a", "x"]:
Expand Down
2 changes: 1 addition & 1 deletion src/ansys/mapdl/core/plotting/plotting_defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def __init__(self):
self._configured = False

def __call__(self, name):
if not self._configured:
if True: # not self._configured: # Temporal patch pending on #3568
self._set_configuration()
self._configured = True

Expand Down
3 changes: 2 additions & 1 deletion src/ansys/mapdl/core/plotting/visualizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -819,6 +819,7 @@ def show(
if savefig:
self._off_screen = True
self._notebook = False

# permit user to save the figure as a screenshot
if self._savefig or savefig:
self._backend.show(
Expand All @@ -833,7 +834,7 @@ def show(
if return_plotter:
return self

# ifplotter.scene.set_background("paraview") not returning plotter, close right away
# if plotter.scene.set_background("paraview") not returning plotter, close right away
self.scene.close()

else:
Expand Down
Binary file modified tests/.image_cache/bc_plot_options[False-False-False].png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/.image_cache/bc_plot_options[False-False-True].png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/.image_cache/bc_plot_options[False-True-False].png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/.image_cache/bc_plot_options[False-True-True].png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/.image_cache/bc_plot_options[True-False-False].png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/.image_cache/bc_plot_options[True-False-True].png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/.image_cache/bc_plot_options[True-True-False].png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/.image_cache/bc_plot_options[True-True-True].png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/.image_cache/bc_plot_options_fields[loads0-field0].png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/.image_cache/bc_plot_options_fields[loads0-field3].png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/.image_cache/bc_plot_options_fields[loads1-field0].png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/.image_cache/bc_plot_options_fields[loads1-field3].png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/.image_cache/bc_plot_options_fields[loads2-field0].png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/.image_cache/bc_plot_options_fields[loads2-field3].png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/.image_cache/bc_plot_options_fields[loads3-field0].png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/.image_cache/bc_plot_options_fields[loads3-field3].png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/.image_cache/single_glyph[0-FY].png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/.image_cache/single_glyph[0-FZ].png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/.image_cache/single_glyph[0-UX].png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/.image_cache/single_glyph[0-UY].png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/.image_cache/single_glyph[0-UZ].png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/.image_cache/single_glyph[50-FX].png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/.image_cache/single_glyph[50-FY].png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/.image_cache/single_glyph[50-FZ].png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/.image_cache/single_glyph[50-UX].png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/.image_cache/single_glyph[50-UY].png
Binary file modified tests/.image_cache/single_glyph[50-UZ].png
Binary file modified tests/.image_cache/single_glyph[500-FX].png
Binary file modified tests/.image_cache/single_glyph[500-FY].png
Binary file modified tests/.image_cache/single_glyph[500-FZ].png
Binary file modified tests/.image_cache/single_glyph[500-UX].png
Binary file modified tests/.image_cache/single_glyph[500-UY].png
Binary file modified tests/.image_cache/single_glyph[500-UZ].png
114 changes: 112 additions & 2 deletions tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,28 @@
"""Shared testing module"""
from collections import namedtuple
import os
from typing import Dict
import subprocess
from typing import Dict, List

import psutil

from ansys.mapdl.core import LOG, Mapdl
from ansys.mapdl.core.errors import MapdlConnectionError, MapdlExitedError
from ansys.mapdl.core.launcher import (
_is_ubuntu,
get_start_instance,
is_ansys_process,
launch_mapdl,
)

from ansys.mapdl.core.launcher import _is_ubuntu
PROCESS_OK_STATUS = [
psutil.STATUS_RUNNING, #
psutil.STATUS_SLEEPING, #
psutil.STATUS_DISK_SLEEP,
psutil.STATUS_DEAD,
psutil.STATUS_PARKED, # (Linux)
psutil.STATUS_IDLE, # (Linux, macOS, FreeBSD)
]

Node = namedtuple("Node", ["number", "x", "y", "z", "thx", "thy", "thz"])
Element = namedtuple(
Expand Down Expand Up @@ -199,3 +218,94 @@ def get_details_of_elements(mapdl_) -> Dict[int, Node]:
if len(args) == 6:
elements[args[0]] = Element(*args, node_numbers=None)
return elements


def log_test_start(mapdl: Mapdl) -> None:
"""Print the current test to the MAPDL log file and console output."""
test_name = os.environ.get(
"PYTEST_CURRENT_TEST", "**test id could not get retrieved.**"
)

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

# To see it also in MAPDL terminal output
if len(test_name) > 75:
# terminal output is limited to 75 characters
test_name = test_name.split("::")
if len(test_name) > 2:
types_ = ["File path", "Test class", "Method"]
else:
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)

else:
mapdl._run(f"/com,Running test: {test_name}", mute=True)


def restart_mapdl(mapdl: Mapdl) -> Mapdl:
"""Restart MAPDL after a failed test"""

def is_exited(mapdl: Mapdl):
try:
_ = mapdl._ctrl("VERSION")
return False
except MapdlExitedError:
return True

if get_start_instance() and (is_exited(mapdl) or mapdl._exited):
# Backing up the current local configuration
local_ = mapdl._local
ip = mapdl.ip
port = mapdl.port
try:
# to connect
mapdl = Mapdl(port=port, ip=ip)

except MapdlConnectionError as err:
# Registering error.
LOG.info(str(err))

# we cannot connect.
# Kill the instance
mapdl.exit()

# Relaunching MAPDL
mapdl = launch_mapdl(
port=mapdl._port,
override=True,
run_location=mapdl._path,
cleanup_on_exit=mapdl._cleanup,
log_apdl=log_apdl(),
)

# Restoring the local configuration
mapdl._local = local_
mapdl._exited = False

return mapdl


def make_sure_not_instances_are_left_open(valid_ports: List) -> None:
"""Make sure we leave no MAPDL running behind"""

if is_on_local():
for proc in psutil.process_iter():
try:
if (
psutil.pid_exists(proc.pid)
and proc.status() in PROCESS_OK_STATUS
and is_ansys_process(proc)
):
cmdline = proc.cmdline()
port = int(cmdline[cmdline.index("-port") + 1])

if port not in valid_ports:
subprocess.run(["pymapdl", "stop", "--port", f"{port}"])
time.sleep(1)
except psutil.NoSuchProcess:
continue
Loading
Loading