diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1ee9df449e..888deef9e0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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, @@ -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: diff --git a/doc/changelog.d/3519.added.md b/doc/changelog.d/3519.added.md new file mode 100644 index 0000000000..4e26bc7b6d --- /dev/null +++ b/doc/changelog.d/3519.added.md @@ -0,0 +1 @@ +refactor: testing suite (random order) \ No newline at end of file diff --git a/doc/source/getting_started/develop_pymapdl.rst b/doc/source/getting_started/develop_pymapdl.rst index 34c261ce3e..242a7ef2f6 100644 --- a/doc/source/getting_started/develop_pymapdl.rst +++ b/doc/source/getting_started/develop_pymapdl.rst @@ -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. diff --git a/pyproject.toml b/pyproject.toml index 7a6a0887ec..37bc304d3d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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 @@ -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", @@ -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", @@ -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", diff --git a/src/ansys/mapdl/core/mapdl_core.py b/src/ansys/mapdl/core/mapdl_core.py index 8855a05019..88eb52fedb 100644 --- a/src/ansys/mapdl/core/mapdl_core.py +++ b/src/ansys/mapdl/core/mapdl_core.py @@ -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"]: diff --git a/src/ansys/mapdl/core/plotting/plotting_defaults.py b/src/ansys/mapdl/core/plotting/plotting_defaults.py index 562af2a585..a734355e36 100644 --- a/src/ansys/mapdl/core/plotting/plotting_defaults.py +++ b/src/ansys/mapdl/core/plotting/plotting_defaults.py @@ -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 diff --git a/src/ansys/mapdl/core/plotting/visualizer.py b/src/ansys/mapdl/core/plotting/visualizer.py index 605e454ade..6f36a527bd 100644 --- a/src/ansys/mapdl/core/plotting/visualizer.py +++ b/src/ansys/mapdl/core/plotting/visualizer.py @@ -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( @@ -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: diff --git a/tests/.image_cache/bc_plot_options[False-False-False].png b/tests/.image_cache/bc_plot_options[False-False-False].png index c4f85c4f80..77e20d8e3c 100644 Binary files a/tests/.image_cache/bc_plot_options[False-False-False].png and b/tests/.image_cache/bc_plot_options[False-False-False].png differ diff --git a/tests/.image_cache/bc_plot_options[False-False-True].png b/tests/.image_cache/bc_plot_options[False-False-True].png index c4f85c4f80..77e20d8e3c 100644 Binary files a/tests/.image_cache/bc_plot_options[False-False-True].png and b/tests/.image_cache/bc_plot_options[False-False-True].png differ diff --git a/tests/.image_cache/bc_plot_options[False-True-False].png b/tests/.image_cache/bc_plot_options[False-True-False].png index bcc571158e..39cf9ba04a 100644 Binary files a/tests/.image_cache/bc_plot_options[False-True-False].png and b/tests/.image_cache/bc_plot_options[False-True-False].png differ diff --git a/tests/.image_cache/bc_plot_options[False-True-True].png b/tests/.image_cache/bc_plot_options[False-True-True].png index bcc571158e..39cf9ba04a 100644 Binary files a/tests/.image_cache/bc_plot_options[False-True-True].png and b/tests/.image_cache/bc_plot_options[False-True-True].png differ diff --git a/tests/.image_cache/bc_plot_options[True-False-False].png b/tests/.image_cache/bc_plot_options[True-False-False].png index 372ab9cae8..21163ec93d 100644 Binary files a/tests/.image_cache/bc_plot_options[True-False-False].png and b/tests/.image_cache/bc_plot_options[True-False-False].png differ diff --git a/tests/.image_cache/bc_plot_options[True-False-True].png b/tests/.image_cache/bc_plot_options[True-False-True].png index 372ab9cae8..21163ec93d 100644 Binary files a/tests/.image_cache/bc_plot_options[True-False-True].png and b/tests/.image_cache/bc_plot_options[True-False-True].png differ diff --git a/tests/.image_cache/bc_plot_options[True-True-False].png b/tests/.image_cache/bc_plot_options[True-True-False].png index c3239ee433..483dc37688 100644 Binary files a/tests/.image_cache/bc_plot_options[True-True-False].png and b/tests/.image_cache/bc_plot_options[True-True-False].png differ diff --git a/tests/.image_cache/bc_plot_options[True-True-True].png b/tests/.image_cache/bc_plot_options[True-True-True].png index c3239ee433..483dc37688 100644 Binary files a/tests/.image_cache/bc_plot_options[True-True-True].png and b/tests/.image_cache/bc_plot_options[True-True-True].png differ diff --git a/tests/.image_cache/bc_plot_options_fields[loads0-field0].png b/tests/.image_cache/bc_plot_options_fields[loads0-field0].png index 97ff8617ca..912bf8d85d 100644 Binary files a/tests/.image_cache/bc_plot_options_fields[loads0-field0].png and b/tests/.image_cache/bc_plot_options_fields[loads0-field0].png differ diff --git a/tests/.image_cache/bc_plot_options_fields[loads0-field3].png b/tests/.image_cache/bc_plot_options_fields[loads0-field3].png index 855d0e215d..001bff1027 100644 Binary files a/tests/.image_cache/bc_plot_options_fields[loads0-field3].png and b/tests/.image_cache/bc_plot_options_fields[loads0-field3].png differ diff --git a/tests/.image_cache/bc_plot_options_fields[loads1-field0].png b/tests/.image_cache/bc_plot_options_fields[loads1-field0].png index 27f64d46fa..e0e26c0578 100644 Binary files a/tests/.image_cache/bc_plot_options_fields[loads1-field0].png and b/tests/.image_cache/bc_plot_options_fields[loads1-field0].png differ diff --git a/tests/.image_cache/bc_plot_options_fields[loads1-field3].png b/tests/.image_cache/bc_plot_options_fields[loads1-field3].png index 8674cab482..8f514e4cd2 100644 Binary files a/tests/.image_cache/bc_plot_options_fields[loads1-field3].png and b/tests/.image_cache/bc_plot_options_fields[loads1-field3].png differ diff --git a/tests/.image_cache/bc_plot_options_fields[loads2-field0].png b/tests/.image_cache/bc_plot_options_fields[loads2-field0].png index cf02ad2672..d203f4c364 100644 Binary files a/tests/.image_cache/bc_plot_options_fields[loads2-field0].png and b/tests/.image_cache/bc_plot_options_fields[loads2-field0].png differ diff --git a/tests/.image_cache/bc_plot_options_fields[loads2-field3].png b/tests/.image_cache/bc_plot_options_fields[loads2-field3].png index a698e6bb31..6dbc09ac34 100644 Binary files a/tests/.image_cache/bc_plot_options_fields[loads2-field3].png and b/tests/.image_cache/bc_plot_options_fields[loads2-field3].png differ diff --git a/tests/.image_cache/bc_plot_options_fields[loads3-field0].png b/tests/.image_cache/bc_plot_options_fields[loads3-field0].png index 167fcb1d1c..f242cf13be 100644 Binary files a/tests/.image_cache/bc_plot_options_fields[loads3-field0].png and b/tests/.image_cache/bc_plot_options_fields[loads3-field0].png differ diff --git a/tests/.image_cache/bc_plot_options_fields[loads3-field3].png b/tests/.image_cache/bc_plot_options_fields[loads3-field3].png index 9509d1d891..e962edd946 100644 Binary files a/tests/.image_cache/bc_plot_options_fields[loads3-field3].png and b/tests/.image_cache/bc_plot_options_fields[loads3-field3].png differ diff --git a/tests/.image_cache/single_glyph[0-FY].png b/tests/.image_cache/single_glyph[0-FY].png index 99e58391bf..d5d650fc0d 100644 Binary files a/tests/.image_cache/single_glyph[0-FY].png and b/tests/.image_cache/single_glyph[0-FY].png differ diff --git a/tests/.image_cache/single_glyph[0-FZ].png b/tests/.image_cache/single_glyph[0-FZ].png index dd38219352..214f7974bc 100644 Binary files a/tests/.image_cache/single_glyph[0-FZ].png and b/tests/.image_cache/single_glyph[0-FZ].png differ diff --git a/tests/.image_cache/single_glyph[0-UX].png b/tests/.image_cache/single_glyph[0-UX].png index c64a3a7c5e..a43167d8c7 100644 Binary files a/tests/.image_cache/single_glyph[0-UX].png and b/tests/.image_cache/single_glyph[0-UX].png differ diff --git a/tests/.image_cache/single_glyph[0-UY].png b/tests/.image_cache/single_glyph[0-UY].png index 003c0f9ce5..8e946f8c75 100644 Binary files a/tests/.image_cache/single_glyph[0-UY].png and b/tests/.image_cache/single_glyph[0-UY].png differ diff --git a/tests/.image_cache/single_glyph[0-UZ].png b/tests/.image_cache/single_glyph[0-UZ].png index f24e57f53b..801d9502e9 100644 Binary files a/tests/.image_cache/single_glyph[0-UZ].png and b/tests/.image_cache/single_glyph[0-UZ].png differ diff --git a/tests/.image_cache/single_glyph[50-FX].png b/tests/.image_cache/single_glyph[50-FX].png index 2f61d294f5..e1aef4d8b3 100644 Binary files a/tests/.image_cache/single_glyph[50-FX].png and b/tests/.image_cache/single_glyph[50-FX].png differ diff --git a/tests/.image_cache/single_glyph[50-FY].png b/tests/.image_cache/single_glyph[50-FY].png index f3932ad9d4..49ad49345e 100644 Binary files a/tests/.image_cache/single_glyph[50-FY].png and b/tests/.image_cache/single_glyph[50-FY].png differ diff --git a/tests/.image_cache/single_glyph[50-FZ].png b/tests/.image_cache/single_glyph[50-FZ].png index 969fc0779e..0870f213a9 100644 Binary files a/tests/.image_cache/single_glyph[50-FZ].png and b/tests/.image_cache/single_glyph[50-FZ].png differ diff --git a/tests/.image_cache/single_glyph[50-UX].png b/tests/.image_cache/single_glyph[50-UX].png index 6ef34721a5..f5a70405b3 100644 Binary files a/tests/.image_cache/single_glyph[50-UX].png and b/tests/.image_cache/single_glyph[50-UX].png differ diff --git a/tests/.image_cache/single_glyph[50-UY].png b/tests/.image_cache/single_glyph[50-UY].png index 9b6bf6f693..132c7fd73f 100644 Binary files a/tests/.image_cache/single_glyph[50-UY].png and b/tests/.image_cache/single_glyph[50-UY].png differ diff --git a/tests/.image_cache/single_glyph[50-UZ].png b/tests/.image_cache/single_glyph[50-UZ].png index 8d674df166..93658b978f 100644 Binary files a/tests/.image_cache/single_glyph[50-UZ].png and b/tests/.image_cache/single_glyph[50-UZ].png differ diff --git a/tests/.image_cache/single_glyph[500-FX].png b/tests/.image_cache/single_glyph[500-FX].png index a286131dc3..ba7e256dc7 100644 Binary files a/tests/.image_cache/single_glyph[500-FX].png and b/tests/.image_cache/single_glyph[500-FX].png differ diff --git a/tests/.image_cache/single_glyph[500-FY].png b/tests/.image_cache/single_glyph[500-FY].png index 89a060f867..f1f142e19d 100644 Binary files a/tests/.image_cache/single_glyph[500-FY].png and b/tests/.image_cache/single_glyph[500-FY].png differ diff --git a/tests/.image_cache/single_glyph[500-FZ].png b/tests/.image_cache/single_glyph[500-FZ].png index a4a3cc9b2a..9ab83b0a5b 100644 Binary files a/tests/.image_cache/single_glyph[500-FZ].png and b/tests/.image_cache/single_glyph[500-FZ].png differ diff --git a/tests/.image_cache/single_glyph[500-UX].png b/tests/.image_cache/single_glyph[500-UX].png index 75a8e2925f..90a66e340d 100644 Binary files a/tests/.image_cache/single_glyph[500-UX].png and b/tests/.image_cache/single_glyph[500-UX].png differ diff --git a/tests/.image_cache/single_glyph[500-UY].png b/tests/.image_cache/single_glyph[500-UY].png index afab9f6f80..2ecc9d525a 100644 Binary files a/tests/.image_cache/single_glyph[500-UY].png and b/tests/.image_cache/single_glyph[500-UY].png differ diff --git a/tests/.image_cache/single_glyph[500-UZ].png b/tests/.image_cache/single_glyph[500-UZ].png index 4a4148d3bc..3b26ccd550 100644 Binary files a/tests/.image_cache/single_glyph[500-UZ].png and b/tests/.image_cache/single_glyph[500-UZ].png differ diff --git a/tests/common.py b/tests/common.py index 749da16324..7187c295d0 100644 --- a/tests/common.py +++ b/tests/common.py @@ -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( @@ -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 diff --git a/tests/conftest.py b/tests/conftest.py index b1c1b6092a..724929fa6d 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -25,17 +25,13 @@ import os from pathlib import Path from shutil import get_terminal_size -import subprocess from sys import platform -import time from unittest.mock import patch from _pytest.terminal import TerminalReporter # for terminal customization -import psutil import pytest from ansys.mapdl.core.helpers import is_installed as has_dependency -from ansys.mapdl.core.launcher import is_ansys_process from common import ( Element, Node, @@ -49,6 +45,9 @@ is_running_on_student, is_smp, log_apdl, + log_test_start, + make_sure_not_instances_are_left_open, + restart_mapdl, support_plotting, testing_minimal, ) @@ -127,16 +126,6 @@ ) -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) -] - - def requires(requirement: str): """Check requirements""" requirement = requirement.lower() @@ -194,7 +183,11 @@ def requires_dependency(dependency: str): return pytest.mark.skip(reason=f"Requires '{dependency}' package") -################ +################################################################ +# +# Importing packages +# ------------------ +# if has_dependency("ansys-tools-package"): from ansys.tools.path import find_mapdl, get_available_ansys_installations @@ -216,19 +209,24 @@ def requires_dependency(dependency: str): pymapdl.RUNNING_TESTS = True from ansys.mapdl.core import Mapdl -from ansys.mapdl.core.errors import ( - MapdlConnectionError, - MapdlExitedError, - MapdlRuntimeError, -) +from ansys.mapdl.core.errors import MapdlExitedError, MapdlRuntimeError from ansys.mapdl.core.examples import vmfiles from ansys.mapdl.core.launcher import get_start_instance, launch_mapdl +from ansys.mapdl.core.mapdl_core import VALID_DEVICES if has_dependency("ansys-tools-visualization_interface"): import ansys.tools.visualization_interface as viz_interface viz_interface.TESTING_MODE = True + +################################################################ +# +# Pytest configuration +# -------------------- +# + + # check if the user wants to permit pytest to start MAPDL START_INSTANCE = get_start_instance() @@ -375,8 +373,8 @@ def pytest_collection_modifyitems(config, items): ################################################################ # -# Setting fixtures -# --------------------------- +# Setting configuration fixtures +# ------------------------------ # if has_dependency("pytest-pyvista"): @@ -445,8 +443,14 @@ def run_before_and_after_tests( assert not mapdl._mapdl_on_hpc, "Mapdl class is on HPC mode. It should not!" assert mapdl.finish_job_on_exit, "Mapdl class should finish the job!" assert not mapdl.ignore_errors, "Mapdl class is ignoring errors!" + assert not mapdl.mute + assert mapdl.file_type_for_plots in VALID_DEVICES - make_sure_not_instances_are_left_open() + # Returning to default + mapdl.graphics("full") + + # Handling extra instances + make_sure_not_instances_are_left_open(VALID_PORTS) # Teardown if mapdl.is_local and mapdl._exited: @@ -460,96 +464,69 @@ def run_before_and_after_tests( ), f"Test {test_name} failed at the teardown." # this will fail the test -def restart_mapdl(mapdl: Mapdl) -> Mapdl: - def is_exited(mapdl: Mapdl): - try: - _ = mapdl._ctrl("VERSION") - return False - except MapdlExitedError: - return True - - if START_INSTANCE and (is_exited(mapdl) or mapdl._exited): - # Backing up the current local configuration - local_ = mapdl._local - channel = mapdl._channel - ip = mapdl.ip - port = mapdl.port - try: - # to connect - mapdl = Mapdl(port=port, ip=ip) - - except MapdlConnectionError as 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, - ) +@pytest.fixture(scope="function") +def set_env_var(request, monkeypatch): + """Set an environment variable from given requests, this fixture must be used with `parametrize`""" + env_var_name = request.param[0] + env_var_value = request.param[1] + monkeypatch.setenv(f"{env_var_name}", f"{env_var_value}") + yield request.param - # Restoring the local configuration - mapdl._local = local_ - mapdl._exited = False - return mapdl +@pytest.fixture(scope="function") +def set_env_var_context(request, monkeypatch): + """Set MY_VARIABLE environment variable, this fixture must be used with `parametrize`""" + if not isinstance(request.param, (tuple, list)): + request_param = [request.param] + else: + request_param = request.param + for each_dict in request_param: + for each_key, each_value in each_dict.items(): + if each_value is not None: + monkeypatch.setenv(f"{each_key}", f"{each_value}") -def log_test_start(mapdl: Mapdl) -> None: - test_name = os.environ.get( - "PYTEST_CURRENT_TEST", "**test id could not get retrieved.**" - ) + yield request.param - 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"] +@pytest.fixture +def path_tests(tmpdir): + SpacedPaths = namedtuple( + "SpacedPaths", + ["path_without_spaces", "path_with_spaces", "path_with_single_quote"], + ) - mapdl._run("/com,Running test in:", mute=True) - for type_, name_ in zip(types_, test_name): - mapdl._run(f"/com, {type_}: {name_}", mute=True) + p1 = tmpdir.mkdir("./temp/") + p2 = tmpdir.mkdir("./t e m p/") + p3 = tmpdir.mkdir("./temp'") + return SpacedPaths(str(p1), str(p2), str(p3)) - else: - mapdl._run(f"/com,Running test: {test_name}", mute=True) +def clear(mapdl): + mapdl.mute = True + mapdl.finish() + # *MUST* be NOSTART. With START fails after 20 calls... + # this has been fixed in later pymapdl and MAPDL releases + mapdl.clear("NOSTART") + mapdl.header("DEFA") + mapdl.format("DEFA") + mapdl.page("DEFA") + + mapdl.prep7() + mapdl.mute = False -def make_sure_not_instances_are_left_open() -> None: - """Make sure we leave no MAPDL running behind""" - if 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) - ): +@pytest.fixture(scope="function") +def cleared(mapdl): + clear(mapdl) + yield - cmdline = proc.cmdline() - port = int(cmdline[cmdline.index("-port") + 1]) - if port not in VALID_PORTS: - cmdline_ = " ".join([f'"{each}"' for each in cmdline]) - subprocess.run(["pymapdl", "stop", "--port", f"{port}"]) - time.sleep(1) - # raise Exception( - # f"The following MAPDL instance running at port {port} is alive after the test.\n" - # f"Only ports {VALID_PORTS} are allowed.\nCMD: {cmdline_}" - # ) - except psutil.NoSuchProcess: - continue +################################################################ +# +# Setting interface fixtures +# -------------------------- +# @pytest.fixture(scope="session") @@ -648,10 +625,11 @@ def mapdl(request, tmpdir_factory): del mapdl -SpacedPaths = namedtuple( - "SpacedPaths", - ["path_without_spaces", "path_with_spaces", "path_with_single_quote"], -) +################################################################ +# +# MAPDL patches +# ------------- +# # Necessary patches to patch Mapdl launch @@ -701,48 +679,33 @@ def _patch_method(method): # Patch all the starting procedures so we can have a pseudo mapdl instance PATCH_MAPDL = [patch(method, ret) for method, ret in _meth_patch_MAPDL] - -@pytest.fixture(scope="function") -def set_env_var(request, monkeypatch): - """Set an environment variable from given requests, this fixture must be used with `parametrize`""" - env_var_name = request.param[0] - env_var_value = request.param[1] - monkeypatch.setenv(f"{env_var_name}", f"{env_var_value}") - yield request.param +################################################################ +# +# TestClass +# --------- +# -@pytest.fixture(scope="function") -def set_env_var_context(request, monkeypatch): - """Set MY_VARIABLE environment variable, this fixture must be used with `parametrize`""" - if not isinstance(request.param, (tuple, list)): - request_param = [request.param] - else: - request_param = request.param +class TestClass: + """Base class for testing. - for each_dict in request_param: - for each_key, each_value in each_dict.items(): - if each_value is not None: - monkeypatch.setenv(f"{each_key}", f"{each_value}") + Provide some helper methods. - yield request.param + This class cleans automatically the MAPDL database upon creation.""" + @pytest.fixture(scope="class", autouse=True) + def initializer(self, mapdl): + self.mapdl = mapdl + self.clear() -@pytest.fixture -def path_tests(tmpdir): - p1 = tmpdir.mkdir("./temp/") - p2 = tmpdir.mkdir("./t e m p/") - p3 = tmpdir.mkdir("./temp'") - return SpacedPaths(str(p1), str(p2), str(p3)) + def clear(self): + clear(self.mapdl) -@pytest.fixture(scope="function") -def cleared(mapdl): - mapdl.finish(mute=True) - # *MUST* be NOSTART. With START fails after 20 calls... - # this has been fixed in later pymapdl and MAPDL releases - mapdl.clear("NOSTART", mute=True) - mapdl.prep7(mute=True) - yield +############################################################ +# Fixtures Models +# ================ +# @pytest.fixture(scope="function") @@ -765,15 +728,9 @@ def cube_solve(cleared, mapdl, cube_geom_and_mesh): out = mapdl.modal_analysis(nmode=10, freqb=1) -@pytest.fixture -def query(mapdl, cleared): - return mapdl.queries - - @pytest.fixture def solved_box(mapdl, cleared): mapdl.mute = True # improve stability - mapdl.prep7() mapdl.et(1, "SOLID5") mapdl.block(0, 10, 0, 20, 0, 30) mapdl.esize(10) @@ -797,52 +754,6 @@ def solved_box(mapdl, cleared): mapdl.finish() mapdl.mute = False - q = mapdl.queries - return q, get_details_of_nodes(mapdl) - - -@pytest.fixture -def common_functions_and_classes(): - return get_details_of_nodes, get_details_of_elements, Node, Element - - -@pytest.fixture -def selection_test_geometry(mapdl, cleared): - mapdl.prep7() - k0 = mapdl.k(1, 0, 0, 0) - k1 = mapdl.k(2, 0, 0, 1) - k2 = mapdl.k(3, 0, 1, 0) - k3 = mapdl.k(4, 1, 0, 0) - v0 = mapdl.v(k0, k1, k2, k3) - mapdl.mshape(1, "3D") - mapdl.et(1, "SOLID98") - mapdl.esize(0.5) - mapdl.vmesh("ALL") - return mapdl.queries - - -def create_geometry(mapdl): - mapdl.prep7() - k0 = mapdl.k(1, 0, 0, 0) - k1 = mapdl.k(2, 0, 5, 0) - k2 = mapdl.k(3, 5, 5, 0) - k3 = mapdl.k(4, 5, 0, 0) - k4 = mapdl.k(5, 0, 0, 5) - k5 = mapdl.k(6, 0, 5, 5) - k6 = mapdl.k(7, 5, 5, 5) - k7 = mapdl.k(8, 5, 0, 5) - a0 = mapdl.a(1, 2, 3, 4) - a1 = mapdl.a(5, 6, 7, 8) - a2 = mapdl.a(3, 4, 8, 7) - a3 = mapdl.a(1, 2, 6, 5) - keypoints = [k0, k1, k2, k3, k4, k5, k6, k7] - areas = [a0, a1, a2, a3] - mapdl.esize(5) - mapdl.mshape(1, "2D") - mapdl.et(1, "SHELL181") - mapdl.amesh("ALL") - return areas, keypoints - @pytest.fixture(scope="function") def make_block(mapdl, cleared): @@ -854,6 +765,7 @@ def make_block(mapdl, cleared): @pytest.fixture(scope="function") def coupled_example(mapdl, cleared): + # TRANSIENT THERMAL STRESS IN A CYLINDER vm33 = vmfiles["vm33"] with open(vm33, "r") as fid: mapdl_code = fid.read() @@ -866,13 +778,10 @@ def coupled_example(mapdl, cleared): @pytest.fixture(scope="function") -def contact_geom_and_mesh(mapdl): +def contact_geom_and_mesh(mapdl, cleared): mapdl.mute = True - mapdl.finish() - mapdl.clear() # Based on tech demo 28. - mapdl.prep7() # ***** Problem parameters ******** l = 76.2e-03 / 3 # Length of each plate,m w = 31.75e-03 / 2 # Width of each plate,m @@ -1146,11 +1055,7 @@ def contact_geom_and_mesh(mapdl): @pytest.fixture(scope="function") -def cuadratic_beam_problem(mapdl): - mapdl.clear() - - # Enter verification example mode and the pre-processing routine. - mapdl.prep7() +def cuadratic_beam_problem(mapdl, cleared): # Type of analysis: static. mapdl.antype("STATIC") @@ -1212,3 +1117,36 @@ def cuadratic_beam_problem(mapdl): mapdl.run("/SOLU") mapdl.solve() mapdl.finish() + + +def create_geometry(mapdl): + mapdl.prep7() + k0 = mapdl.k(1, 0, 0, 0) + k1 = mapdl.k(2, 0, 5, 0) + k2 = mapdl.k(3, 5, 5, 0) + k3 = mapdl.k(4, 5, 0, 0) + k4 = mapdl.k(5, 0, 0, 5) + k5 = mapdl.k(6, 0, 5, 5) + k6 = mapdl.k(7, 5, 5, 5) + k7 = mapdl.k(8, 5, 0, 5) + a0 = mapdl.a(1, 2, 3, 4) + a1 = mapdl.a(5, 6, 7, 8) + a2 = mapdl.a(3, 4, 8, 7) + a3 = mapdl.a(1, 2, 6, 5) + keypoints = [k0, k1, k2, k3, k4, k5, k6, k7] + areas = [a0, a1, a2, a3] + mapdl.esize(5) + mapdl.mshape(1, "2D") + mapdl.et(1, "SHELL181") + mapdl.amesh("ALL") + return areas, keypoints + + +@pytest.fixture +def query(mapdl, cleared): + return mapdl.queries + + +@pytest.fixture +def common_functions_and_classes(): + return get_details_of_nodes, get_details_of_elements, Node, Element diff --git a/tests/test_commands.py b/tests/test_commands.py index 51573fb4a0..ffc4047e98 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -26,7 +26,6 @@ import numpy as np import pytest -from ansys.mapdl.core import examples from ansys.mapdl.core.commands import ( CMD_BC_LISTING, CMD_LISTING, @@ -36,8 +35,8 @@ Commands, StringWithLiteralRepr, ) -from ansys.mapdl.core.examples import verif_files -from conftest import has_dependency, requires +from ansys.mapdl.core.examples.verif_files import vmfiles +from conftest import TestClass, has_dependency, requires if has_dependency("pandas"): import pandas as pd @@ -140,418 +139,14 @@ VALUE -0.37253E-008 0.46566E-009 """ -DLIST_RESULT = [ - ["1", "UX", "0.00000000", "0.00000000"], - ["1", "UY", "0.00000000", "0.00000000"], - ["1", "UZ", "0.00000000", "0.00000000"], - ["1", "TEMP", "300.000000", "0.00000000"], - ["2", "UX", "0.00000000", "0.00000000"], - ["2", "UY", "0.00000000", "0.00000000"], - ["2", "UZ", "0.00000000", "0.00000000"], - ["2", "TEMP", "300.000000", "0.00000000"], - ["3", "UX", "0.00000000", "0.00000000"], - ["3", "UY", "0.00000000", "0.00000000"], - ["3", "UZ", "0.00000000", "0.00000000"], - ["3", "TEMP", "300.000000", "0.00000000"], - ["4", "UX", "0.00000000", "0.00000000"], - ["4", "UY", "0.00000000", "0.00000000"], - ["4", "UZ", "0.00000000", "0.00000000"], - ["4", "TEMP", "300.000000", "0.00000000"], - ["5", "UX", "0.00000000", "0.00000000"], - ["5", "UY", "0.00000000", "0.00000000"], - ["5", "UZ", "0.00000000", "0.00000000"], - ["5", "TEMP", "300.000000", "0.00000000"], - ["6", "UX", "0.00000000", "0.00000000"], - ["6", "UY", "0.00000000", "0.00000000"], - ["6", "UZ", "0.00000000", "0.00000000"], - ["6", "TEMP", "300.000000", "0.00000000"], - ["7", "UX", "0.00000000", "0.00000000"], - ["7", "UY", "0.00000000", "0.00000000"], - ["7", "UZ", "0.00000000", "0.00000000"], - ["7", "TEMP", "300.000000", "0.00000000"], - ["8", "UX", "0.00000000", "0.00000000"], - ["8", "UY", "0.00000000", "0.00000000"], - ["8", "UZ", "0.00000000", "0.00000000"], - ["8", "TEMP", "300.000000", "0.00000000"], - ["9", "UX", "0.00000000", "0.00000000"], - ["9", "UY", "0.00000000", "0.00000000"], - ["9", "UZ", "0.00000000", "0.00000000"], - ["9", "TEMP", "300.000000", "0.00000000"], - ["10", "UX", "0.00000000", "0.00000000"], - ["10", "UY", "0.00000000", "0.00000000"], - ["10", "UZ", "0.00000000", "0.00000000"], - ["10", "TEMP", "300.000000", "0.00000000"], - ["11", "UX", "0.00000000", "0.00000000"], - ["11", "UY", "0.00000000", "0.00000000"], - ["11", "UZ", "0.00000000", "0.00000000"], - ["11", "TEMP", "300.000000", "0.00000000"], - ["12", "UX", "0.00000000", "0.00000000"], - ["12", "UY", "0.00000000", "0.00000000"], - ["12", "UZ", "0.00000000", "0.00000000"], - ["12", "TEMP", "300.000000", "0.00000000"], - ["13", "UX", "0.00000000", "0.00000000"], - ["13", "UY", "0.00000000", "0.00000000"], - ["13", "UZ", "0.00000000", "0.00000000"], - ["13", "TEMP", "300.000000", "0.00000000"], - ["146", "UX", "0.00000000", "0.00000000"], - ["146", "UY", "0.00000000", "0.00000000"], - ["146", "UZ", "0.00000000", "0.00000000"], - ["146", "TEMP", "300.000000", "0.00000000"], - ["158", "UX", "0.00000000", "0.00000000"], - ["158", "UY", "0.00000000", "0.00000000"], - ["158", "UZ", "0.00000000", "0.00000000"], - ["158", "TEMP", "300.000000", "0.00000000"], - ["159", "UX", "0.00000000", "0.00000000"], - ["159", "UY", "0.00000000", "0.00000000"], - ["159", "UZ", "0.00000000", "0.00000000"], - ["159", "TEMP", "300.000000", "0.00000000"], - ["160", "UX", "0.00000000", "0.00000000"], - ["160", "UY", "0.00000000", "0.00000000"], - ["160", "UZ", "0.00000000", "0.00000000"], - ["160", "TEMP", "300.000000", "0.00000000"], - ["161", "UX", "0.00000000", "0.00000000"], - ["161", "UY", "0.00000000", "0.00000000"], - ["161", "UZ", "0.00000000", "0.00000000"], - ["161", "TEMP", "300.000000", "0.00000000"], - ["162", "UX", "0.00000000", "0.00000000"], - ["162", "UY", "0.00000000", "0.00000000"], - ["162", "UZ", "0.00000000", "0.00000000"], - ["162", "TEMP", "300.000000", "0.00000000"], - ["163", "UX", "0.00000000", "0.00000000"], - ["163", "UY", "0.00000000", "0.00000000"], - ["163", "UZ", "0.00000000", "0.00000000"], - ["163", "TEMP", "300.000000", "0.00000000"], - ["164", "UX", "0.00000000", "0.00000000"], - ["164", "UY", "0.00000000", "0.00000000"], - ["164", "UZ", "0.00000000", "0.00000000"], - ["164", "TEMP", "300.000000", "0.00000000"], - ["165", "UX", "0.00000000", "0.00000000"], - ["165", "UY", "0.00000000", "0.00000000"], - ["165", "UZ", "0.00000000", "0.00000000"], - ["165", "TEMP", "300.000000", "0.00000000"], - ["166", "UX", "0.00000000", "0.00000000"], - ["166", "UY", "0.00000000", "0.00000000"], - ["166", "UZ", "0.00000000", "0.00000000"], - ["166", "TEMP", "300.000000", "0.00000000"], - ["167", "UX", "0.00000000", "0.00000000"], - ["167", "UY", "0.00000000", "0.00000000"], - ["167", "UZ", "0.00000000", "0.00000000"], - ["167", "TEMP", "300.000000", "0.00000000"], - ["168", "UX", "0.00000000", "0.00000000"], - ["168", "UY", "0.00000000", "0.00000000"], - ["168", "UZ", "0.00000000", "0.00000000"], - ["168", "TEMP", "300.000000", "0.00000000"], - ["169", "UX", "0.00000000", "0.00000000"], - ["169", "UY", "0.00000000", "0.00000000"], - ["169", "UZ", "0.00000000", "0.00000000"], - ["169", "TEMP", "300.000000", "0.00000000"], - ["171", "UX", "0.00000000", "0.00000000"], - ["171", "UY", "0.00000000", "0.00000000"], - ["171", "UZ", "0.00000000", "0.00000000"], - ["171", "TEMP", "300.000000", "0.00000000"], - ["172", "UX", "0.00000000", "0.00000000"], - ["172", "UY", "0.00000000", "0.00000000"], - ["172", "UZ", "0.00000000", "0.00000000"], - ["172", "TEMP", "300.000000", "0.00000000"], - ["173", "UX", "0.00000000", "0.00000000"], - ["173", "UY", "0.00000000", "0.00000000"], - ["173", "UZ", "0.00000000", "0.00000000"], - ["173", "TEMP", "300.000000", "0.00000000"], - ["174", "UX", "0.00000000", "0.00000000"], - ["174", "UY", "0.00000000", "0.00000000"], - ["174", "UZ", "0.00000000", "0.00000000"], - ["174", "TEMP", "300.000000", "0.00000000"], - ["175", "UX", "0.00000000", "0.00000000"], - ["175", "UY", "0.00000000", "0.00000000"], - ["175", "UZ", "0.00000000", "0.00000000"], - ["175", "TEMP", "300.000000", "0.00000000"], - ["176", "UX", "0.00000000", "0.00000000"], - ["176", "UY", "0.00000000", "0.00000000"], - ["176", "UZ", "0.00000000", "0.00000000"], - ["176", "TEMP", "300.000000", "0.00000000"], - ["177", "UX", "0.00000000", "0.00000000"], - ["177", "UY", "0.00000000", "0.00000000"], - ["177", "UZ", "0.00000000", "0.00000000"], - ["177", "TEMP", "300.000000", "0.00000000"], - ["178", "UX", "0.00000000", "0.00000000"], - ["178", "UY", "0.00000000", "0.00000000"], - ["178", "UZ", "0.00000000", "0.00000000"], - ["178", "TEMP", "300.000000", "0.00000000"], - ["179", "UX", "0.00000000", "0.00000000"], - ["179", "UY", "0.00000000", "0.00000000"], - ["179", "UZ", "0.00000000", "0.00000000"], - ["179", "TEMP", "300.000000", "0.00000000"], - ["314", "UX", "0.00000000", "0.00000000"], - ["314", "UY", "0.00000000", "0.00000000"], - ["314", "UZ", "0.00000000", "0.00000000"], - ["314", "TEMP", "300.000000", "0.00000000"], - ["315", "UX", "0.00000000", "0.00000000"], - ["315", "UY", "0.00000000", "0.00000000"], - ["315", "UZ", "0.00000000", "0.00000000"], - ["315", "TEMP", "300.000000", "0.00000000"], - ["316", "UX", "0.00000000", "0.00000000"], - ["316", "UY", "0.00000000", "0.00000000"], - ["316", "UZ", "0.00000000", "0.00000000"], - ["316", "TEMP", "300.000000", "0.00000000"], - ["317", "UX", "0.00000000", "0.00000000"], - ["317", "UY", "0.00000000", "0.00000000"], - ["317", "UZ", "0.00000000", "0.00000000"], - ["317", "TEMP", "300.000000", "0.00000000"], - ["318", "UX", "0.00000000", "0.00000000"], - ["318", "UY", "0.00000000", "0.00000000"], - ["318", "UZ", "0.00000000", "0.00000000"], - ["318", "TEMP", "300.000000", "0.00000000"], - ["319", "UX", "0.00000000", "0.00000000"], - ["319", "UY", "0.00000000", "0.00000000"], - ["319", "UZ", "0.00000000", "0.00000000"], - ["319", "TEMP", "300.000000", "0.00000000"], - ["320", "UX", "0.00000000", "0.00000000"], - ["320", "UY", "0.00000000", "0.00000000"], - ["320", "UZ", "0.00000000", "0.00000000"], - ["320", "TEMP", "300.000000", "0.00000000"], - ["321", "UX", "0.00000000", "0.00000000"], - ["321", "UY", "0.00000000", "0.00000000"], - ["321", "UZ", "0.00000000", "0.00000000"], - ["321", "TEMP", "300.000000", "0.00000000"], - ["322", "UX", "0.00000000", "0.00000000"], - ["322", "UY", "0.00000000", "0.00000000"], - ["322", "UZ", "0.00000000", "0.00000000"], - ["322", "TEMP", "300.000000", "0.00000000"], - ["323", "UX", "0.00000000", "0.00000000"], - ["323", "UY", "0.00000000", "0.00000000"], - ["323", "UZ", "0.00000000", "0.00000000"], - ["323", "TEMP", "300.000000", "0.00000000"], - ["324", "UX", "0.00000000", "0.00000000"], - ["324", "UY", "0.00000000", "0.00000000"], - ["324", "UZ", "0.00000000", "0.00000000"], - ["324", "TEMP", "300.000000", "0.00000000"], - ["330", "UX", "0.00000000", "0.00000000"], - ["330", "UY", "0.00000000", "0.00000000"], - ["330", "UZ", "0.00000000", "0.00000000"], - ["330", "TEMP", "300.000000", "0.00000000"], - ["331", "UX", "0.00000000", "0.00000000"], - ["331", "UY", "0.00000000", "0.00000000"], - ["331", "UZ", "0.00000000", "0.00000000"], - ["331", "TEMP", "300.000000", "0.00000000"], - ["332", "UX", "0.00000000", "0.00000000"], - ["332", "UY", "0.00000000", "0.00000000"], - ["332", "UZ", "0.00000000", "0.00000000"], - ["332", "TEMP", "300.000000", "0.00000000"], - ["334", "UX", "0.00000000", "0.00000000"], - ["334", "UY", "0.00000000", "0.00000000"], - ["334", "UZ", "0.00000000", "0.00000000"], - ["334", "TEMP", "300.000000", "0.00000000"], - ["335", "UX", "0.00000000", "0.00000000"], - ["335", "UY", "0.00000000", "0.00000000"], - ["335", "UZ", "0.00000000", "0.00000000"], - ["335", "TEMP", "300.000000", "0.00000000"], - ["336", "UX", "0.00000000", "0.00000000"], - ["336", "UY", "0.00000000", "0.00000000"], - ["336", "UZ", "0.00000000", "0.00000000"], - ["336", "TEMP", "300.000000", "0.00000000"], - ["340", "UX", "0.00000000", "0.00000000"], - ["340", "UY", "0.00000000", "0.00000000"], - ["340", "UZ", "0.00000000", "0.00000000"], - ["340", "TEMP", "300.000000", "0.00000000"], - ["341", "UX", "0.00000000", "0.00000000"], - ["341", "UY", "0.00000000", "0.00000000"], - ["341", "UZ", "0.00000000", "0.00000000"], - ["341", "TEMP", "300.000000", "0.00000000"], - ["342", "UX", "0.00000000", "0.00000000"], - ["342", "UY", "0.00000000", "0.00000000"], - ["342", "UZ", "0.00000000", "0.00000000"], - ["342", "TEMP", "300.000000", "0.00000000"], - ["343", "UX", "0.00000000", "0.00000000"], - ["343", "UY", "0.00000000", "0.00000000"], - ["343", "UZ", "0.00000000", "0.00000000"], - ["343", "TEMP", "300.000000", "0.00000000"], - ["348", "UX", "0.00000000", "0.00000000"], - ["348", "UY", "0.00000000", "0.00000000"], - ["348", "UZ", "0.00000000", "0.00000000"], - ["348", "TEMP", "300.000000", "0.00000000"], - ["349", "UX", "0.00000000", "0.00000000"], - ["349", "UY", "0.00000000", "0.00000000"], - ["349", "UZ", "0.00000000", "0.00000000"], - ["349", "TEMP", "300.000000", "0.00000000"], - ["350", "UX", "0.00000000", "0.00000000"], - ["350", "UY", "0.00000000", "0.00000000"], - ["350", "UZ", "0.00000000", "0.00000000"], - ["350", "TEMP", "300.000000", "0.00000000"], - ["351", "UX", "0.00000000", "0.00000000"], - ["351", "UY", "0.00000000", "0.00000000"], - ["351", "UZ", "0.00000000", "0.00000000"], - ["351", "TEMP", "300.000000", "0.00000000"], - ["352", "UX", "0.00000000", "0.00000000"], - ["352", "UY", "0.00000000", "0.00000000"], - ["352", "UZ", "0.00000000", "0.00000000"], - ["352", "TEMP", "300.000000", "0.00000000"], - ["353", "UX", "0.00000000", "0.00000000"], - ["353", "UY", "0.00000000", "0.00000000"], - ["353", "UZ", "0.00000000", "0.00000000"], - ["353", "TEMP", "300.000000", "0.00000000"], - ["354", "UX", "0.00000000", "0.00000000"], - ["354", "UY", "0.00000000", "0.00000000"], - ["354", "UZ", "0.00000000", "0.00000000"], - ["354", "TEMP", "300.000000", "0.00000000"], - ["355", "UX", "0.00000000", "0.00000000"], - ["355", "UY", "0.00000000", "0.00000000"], - ["355", "UZ", "0.00000000", "0.00000000"], - ["355", "TEMP", "300.000000", "0.00000000"], - ["356", "UX", "0.00000000", "0.00000000"], - ["356", "UY", "0.00000000", "0.00000000"], - ["356", "UZ", "0.00000000", "0.00000000"], - ["356", "TEMP", "300.000000", "0.00000000"], - ["357", "UX", "0.00000000", "0.00000000"], - ["357", "UY", "0.00000000", "0.00000000"], - ["357", "UZ", "0.00000000", "0.00000000"], - ["357", "TEMP", "300.000000", "0.00000000"], - ["358", "UX", "0.00000000", "0.00000000"], - ["358", "UY", "0.00000000", "0.00000000"], - ["358", "UZ", "0.00000000", "0.00000000"], - ["358", "TEMP", "300.000000", "0.00000000"], - ["359", "UX", "0.00000000", "0.00000000"], - ["359", "UY", "0.00000000", "0.00000000"], - ["359", "UZ", "0.00000000", "0.00000000"], - ["359", "TEMP", "300.000000", "0.00000000"], - ["360", "UX", "0.00000000", "0.00000000"], - ["360", "UY", "0.00000000", "0.00000000"], - ["360", "UZ", "0.00000000", "0.00000000"], - ["360", "TEMP", "300.000000", "0.00000000"], - ["361", "UX", "0.00000000", "0.00000000"], - ["361", "UY", "0.00000000", "0.00000000"], - ["361", "UZ", "0.00000000", "0.00000000"], - ["361", "TEMP", "300.000000", "0.00000000"], - ["362", "UX", "0.00000000", "0.00000000"], - ["362", "UY", "0.00000000", "0.00000000"], - ["362", "UZ", "0.00000000", "0.00000000"], - ["362", "TEMP", "300.000000", "0.00000000"], - ["363", "UX", "0.00000000", "0.00000000"], - ["363", "UY", "0.00000000", "0.00000000"], - ["363", "UZ", "0.00000000", "0.00000000"], - ["363", "TEMP", "300.000000", "0.00000000"], - ["364", "UX", "0.00000000", "0.00000000"], - ["364", "UY", "0.00000000", "0.00000000"], - ["364", "UZ", "0.00000000", "0.00000000"], - ["364", "TEMP", "300.000000", "0.00000000"], - ["365", "UX", "0.00000000", "0.00000000"], - ["365", "UY", "0.00000000", "0.00000000"], - ["365", "UZ", "0.00000000", "0.00000000"], - ["365", "TEMP", "300.000000", "0.00000000"], - ["366", "UX", "0.00000000", "0.00000000"], - ["366", "UY", "0.00000000", "0.00000000"], - ["366", "UZ", "0.00000000", "0.00000000"], - ["366", "TEMP", "300.000000", "0.00000000"], - ["520", "UX", "0.00000000", "0.00000000"], - ["520", "UY", "0.00000000", "0.00000000"], - ["520", "UZ", "0.00000000", "0.00000000"], - ["520", "TEMP", "300.000000", "0.00000000"], - ["572", "UX", "0.00000000", "0.00000000"], - ["572", "UY", "0.00000000", "0.00000000"], - ["572", "UZ", "0.00000000", "0.00000000"], - ["572", "TEMP", "300.000000", "0.00000000"], - ["573", "UX", "0.00000000", "0.00000000"], - ["573", "UY", "0.00000000", "0.00000000"], - ["573", "UZ", "0.00000000", "0.00000000"], - ["573", "TEMP", "300.000000", "0.00000000"], - ["574", "UX", "0.00000000", "0.00000000"], - ["574", "UY", "0.00000000", "0.00000000"], - ["574", "UZ", "0.00000000", "0.00000000"], - ["574", "TEMP", "300.000000", "0.00000000"], - ["575", "UX", "0.00000000", "0.00000000"], - ["575", "UY", "0.00000000", "0.00000000"], - ["575", "UZ", "0.00000000", "0.00000000"], - ["575", "TEMP", "300.000000", "0.00000000"], - ["576", "UX", "0.00000000", "0.00000000"], - ["576", "UY", "0.00000000", "0.00000000"], - ["576", "UZ", "0.00000000", "0.00000000"], - ["576", "TEMP", "300.000000", "0.00000000"], - ["628", "UX", "0.00000000", "0.00000000"], - ["628", "UY", "0.00000000", "0.00000000"], - ["628", "UZ", "0.00000000", "0.00000000"], - ["628", "TEMP", "300.000000", "0.00000000"], - ["645", "UX", "0.00000000", "0.00000000"], - ["645", "UY", "0.00000000", "0.00000000"], - ["645", "UZ", "0.00000000", "0.00000000"], - ["645", "TEMP", "300.000000", "0.00000000"], - ["708", "UX", "0.00000000", "0.00000000"], - ["708", "UY", "0.00000000", "0.00000000"], - ["708", "UZ", "0.00000000", "0.00000000"], - ["708", "TEMP", "300.000000", "0.00000000"], - ["709", "UX", "0.00000000", "0.00000000"], - ["709", "UY", "0.00000000", "0.00000000"], - ["709", "UZ", "0.00000000", "0.00000000"], - ["709", "TEMP", "300.000000", "0.00000000"], - ["710", "UX", "0.00000000", "0.00000000"], - ["710", "UY", "0.00000000", "0.00000000"], - ["710", "UZ", "0.00000000", "0.00000000"], - ["710", "TEMP", "300.000000", "0.00000000"], - ["711", "UX", "0.00000000", "0.00000000"], - ["711", "UY", "0.00000000", "0.00000000"], - ["711", "UZ", "0.00000000", "0.00000000"], - ["711", "TEMP", "300.000000", "0.00000000"], - ["712", "UX", "0.00000000", "0.00000000"], - ["712", "UY", "0.00000000", "0.00000000"], - ["712", "UZ", "0.00000000", "0.00000000"], - ["712", "TEMP", "300.000000", "0.00000000"], - ["713", "UX", "0.00000000", "0.00000000"], - ["713", "UY", "0.00000000", "0.00000000"], - ["713", "UZ", "0.00000000", "0.00000000"], - ["713", "TEMP", "300.000000", "0.00000000"], - ["757", "UX", "0.00000000", "0.00000000"], - ["757", "UY", "0.00000000", "0.00000000"], - ["757", "UZ", "0.00000000", "0.00000000"], - ["757", "TEMP", "300.000000", "0.00000000"], - ["758", "UX", "0.00000000", "0.00000000"], - ["758", "UY", "0.00000000", "0.00000000"], - ["758", "UZ", "0.00000000", "0.00000000"], - ["758", "TEMP", "300.000000", "0.00000000"], - ["784", "UX", "0.00000000", "0.00000000"], - ["784", "UY", "0.00000000", "0.00000000"], - ["784", "UZ", "0.00000000", "0.00000000"], - ["784", "TEMP", "300.000000", "0.00000000"], - ["785", "UX", "0.00000000", "0.00000000"], - ["785", "UY", "0.00000000", "0.00000000"], - ["785", "UZ", "0.00000000", "0.00000000"], - ["785", "TEMP", "300.000000", "0.00000000"], - ["831", "UX", "0.00000000", "0.00000000"], - ["831", "UY", "0.00000000", "0.00000000"], - ["831", "UZ", "0.00000000", "0.00000000"], - ["831", "TEMP", "300.000000", "0.00000000"], - ["832", "UX", "0.00000000", "0.00000000"], - ["832", "UY", "0.00000000", "0.00000000"], - ["832", "UZ", "0.00000000", "0.00000000"], - ["832", "TEMP", "300.000000", "0.00000000"], - ["833", "UX", "0.00000000", "0.00000000"], - ["833", "UY", "0.00000000", "0.00000000"], - ["833", "UZ", "0.00000000", "0.00000000"], - ["833", "TEMP", "300.000000", "0.00000000"], - ["835", "UX", "0.00000000", "0.00000000"], - ["835", "UY", "0.00000000", "0.00000000"], - ["835", "UZ", "0.00000000", "0.00000000"], -] - CMD_DOC_STRING_INJECTOR = CMD_LISTING.copy() CMD_DOC_STRING_INJECTOR.extend(CMD_BC_LISTING) -@pytest.fixture(scope="module") -def plastic_solve(mapdl): +@pytest.fixture() +def beam_solve(mapdl, cleared): mapdl.mute = True - mapdl.finish() - mapdl.clear() - mapdl.input(examples.verif_files.vmfiles["vm273"]) - - mapdl.post1() - mapdl.set(1, 2) - mapdl.mute = False - - -@pytest.fixture(scope="module") -def beam_solve(mapdl): - mapdl.mute = True - mapdl.finish() - mapdl.clear() - mapdl.input(examples.verif_files.vmfiles["vm10"]) + mapdl.input(vmfiles["vm10"]) mapdl.post1() mapdl.set(1, 2) @@ -596,32 +191,50 @@ def test_cmd_class_prnsol_short(): def test_cmd_class_dlist_vm(mapdl, cleared): # Run only the first 100 lines of VM223 - with open(verif_files.vmfiles["vm223"]) as fid: - cmds = fid.read() + DLIST_RESULT = [ + ["1", "UX", "10.0000000", "0.00000000"], + ["3", "TEMP", "10.0000000", "0.00000000"], + ["5", "UZ", "0.00000000", "0.00000000"], + ["10", "UX", "0.00000000", "0.00000000"], + ["10", "UY", "0.00000000", "0.00000000"], + ["10", "UZ", "0.00000000", "0.00000000"], + ["10", "TEMP", "0.00000000", "0.00000000"], + ["10", "VOLT", "0.00000000", "0.00000000"], + ["11", "TEMP", "20.0000000", "0.00000000"], + ] + mapdl.allsel() + mapdl.prep7() + mapdl.et(1, "SOLID227", 111) + mapdl.block(0, 10, 0, 20, 0, 30) + mapdl.esize(10) + mapdl.vmesh("ALL") + + mapdl.d(1, "UX", 10) + mapdl.d(3, "TEMP", 10) + mapdl.d(5, "UZ", 0) - mapdl.finish() - ind = cmds.find("NSEL,ALL") - mapdl.input_strings(cmds[:ind]) + mapdl.d(10, "ALL", 0) + mapdl.d(11, "TEMP", 20) + mapdl.d(11, "VOLT", 20) mapdl.allsel("all") out = mapdl.dlist() out_list = out.to_list() - def are_the_same_result(): - for el1, el2 in zip(out_list, DLIST_RESULT): + def are_the_same_result(a, b): + for el1, el2 in zip(a, b): for el11, el22 in zip(el1, el2): - if el11 != el22: - return False + assert el11 == el22 return True assert isinstance(out, BoundaryConditionsListingOutput) assert isinstance(out_list, list) assert out_list - assert are_the_same_result() + assert are_the_same_result(out_list, DLIST_RESULT) @pytest.mark.parametrize("func", LIST_OF_INQUIRE_FUNCTIONS) -def test_inquire_functions(mapdl, func): +def test_inquire_functions(mapdl, cleared, func): func_ = getattr(mapdl, func) func_args = inspect.getfullargspec(func_).args args = [ @@ -635,27 +248,6 @@ def test_inquire_functions(mapdl, func): assert "=" in output -@pytest.mark.parametrize( - "func,args", - [("prnsol", ("U", "X")), ("presol", ("S", "X")), ("presol", ("S", "ALL"))], -) -def test_output_listing(mapdl, plastic_solve, func, args): - mapdl.post1() - func_ = getattr(mapdl, func) - out = func_(*args) - - out_list = out.to_list() - out_array = out.to_array() - - assert isinstance(out, CommandListingOutput) - assert isinstance(out_list, list) and out_list - assert isinstance(out_array, np.ndarray) and out_array.size != 0 - - if has_dependency("pandas"): - out_df = out.to_dataframe() - assert isinstance(out_df, pd.DataFrame) and not out_df.empty - - @pytest.mark.parametrize("func", ["dlist", "flist"]) def test_bclist(mapdl, beam_solve, func): func_ = getattr(mapdl, func) @@ -674,7 +266,7 @@ def test_bclist(mapdl, beam_solve, func): @pytest.mark.parametrize("method", CMD_DOC_STRING_INJECTOR) -def test_docstring_injector(mapdl, method): +def test_docstring_injector(mapdl, cleared, method): """Check if the docstring has been injected.""" for name in dir(mapdl): if name[0:4].upper() == method and name in dir( @@ -736,10 +328,7 @@ def test_nlist_to_array(mapdl, beam_solve): assert np.allclose(nlist.to_array()[:, 1:4], mapdl.mesh.nodes) -def test_cmlist(mapdl): - mapdl.clear() - - mapdl.prep7() +def test_cmlist(mapdl, cleared): # setup the full file mapdl.block(0, 1, 0, 1, 0, 1) mapdl.et(1, 186) @@ -769,40 +358,40 @@ def test_cmlist(mapdl): assert each_ in cmlist_all -class Test_bc_cmdlist_solid: +def solid_FE_model(mapdl): + # Define keypoints, lines and area + # -------------------- + mapdl.k(1, 0, 0) + mapdl.k(2, 1, 0) + mapdl.k(3, 1, 1) + mapdl.l(1, 2) + mapdl.l(2, 3) + mapdl.l(3, 1) + mapdl.a(1, 2, 3) - def solid_model(self, mapdl): - # Solid model (Geometry) + # Define a material + # -------------------- + mapdl.mp("EX", 1, 30e6) + mapdl.mp("NUXY", 1, 0.25) # Poisson's Ratio - mapdl.clear() + # Define section + # -------------------- + mapdl.et(1, "PLANE183") + mapdl.keyopt(1, 1, 0) + mapdl.keyopt(1, 3, 3) + mapdl.keyopt(1, 6, 0) + mapdl.r(1, 0.01) - mapdl.prep7() - # Define keypoints, lines and area - # -------------------- - mapdl.k(1, 0, 0) - mapdl.k(2, 1, 0) - mapdl.k(3, 1, 1) - mapdl.l(1, 2) - mapdl.l(2, 3) - mapdl.l(3, 1) - mapdl.a(1, 2, 3) +class Test_bc_cmdlist_solid(TestClass): - # Define a material - # -------------------- - mapdl.mp("EX", 1, 30e6) - mapdl.mp("NUXY", 1, 0.25) # Poisson's Ratio - - # Define section - # -------------------- - mapdl.et(1, "PLANE183") - mapdl.keyopt(1, 1, 0) - mapdl.keyopt(1, 3, 3) - mapdl.keyopt(1, 6, 0) - mapdl.r(1, 0.01) + @staticmethod + @pytest.fixture(scope="class") + def solid_model(mapdl): + solid_FE_model(mapdl) @requires("pandas") - def test_dklist(self, mapdl): + def test_dklist(self, mapdl, solid_model): df_dk = pd.DataFrame( { @@ -813,8 +402,6 @@ def test_dklist(self, mapdl): "EXP KEY": ["0"], } ) - - self.solid_model(mapdl) mapdl.dk(1, "UX", 0) dklist_result = mapdl.dklist().to_dataframe() @@ -823,7 +410,7 @@ def test_dklist(self, mapdl): assert dklist_result.compare(df_dk).empty @requires("pandas") - def test_dllist(self, mapdl): + def test_dllist(self, mapdl, solid_model): df_dl = pd.DataFrame( { @@ -835,7 +422,6 @@ def test_dllist(self, mapdl): } ) - self.solid_model(mapdl) mapdl.dl(2, 1, "ALL", 0) dllist_result = mapdl.dllist().to_dataframe() @@ -844,7 +430,7 @@ def test_dllist(self, mapdl): assert dllist_result.compare(df_dl).empty @requires("pandas") - def test_dalist(self, mapdl): + def test_dalist(self, mapdl, solid_model): df_da = pd.DataFrame( { @@ -855,7 +441,6 @@ def test_dalist(self, mapdl): } ) - self.solid_model(mapdl) mapdl.da(1, "UZ", 0) dalist_result = mapdl.dalist().to_dataframe() @@ -864,7 +449,7 @@ def test_dalist(self, mapdl): assert dalist_result.compare(df_da).empty @requires("pandas") - def test_fklist(self, mapdl): + def test_fklist(self, mapdl, solid_model): df_fk = pd.DataFrame( { @@ -875,7 +460,6 @@ def test_fklist(self, mapdl): } ) - self.solid_model(mapdl) mapdl.fk(2, "FY", 200) mapdl.fk(3, "FY", 100) @@ -885,7 +469,7 @@ def test_fklist(self, mapdl): assert fklist_result.compare(df_fk).empty @requires("pandas") - def test_sfllist(self, mapdl): + def test_sfllist(self, mapdl, solid_model): df_sfl = pd.DataFrame( { @@ -896,7 +480,6 @@ def test_sfllist(self, mapdl): } ) - self.solid_model(mapdl) mapdl.sfl(2, "PRES", 50, 500) mapdl.sfl(3, "PRES", 50, 500) @@ -906,7 +489,7 @@ def test_sfllist(self, mapdl): assert sfllist_result.compare(df_sfl).empty @requires("pandas") - def test_bfklist(self, mapdl): + def test_bfklist(self, mapdl, solid_model): df_bfk = pd.DataFrame( { @@ -916,7 +499,6 @@ def test_bfklist(self, mapdl): } ) - self.solid_model(mapdl) mapdl.bfk(2, "TEMP", 10) bfklist_result = mapdl.bfklist().to_dataframe() @@ -925,7 +507,7 @@ def test_bfklist(self, mapdl): assert bfklist_result.compare(df_bfk).empty @requires("pandas") - def test_bfllist(self, mapdl): + def test_bfllist(self, mapdl, solid_model): df_bfl = pd.DataFrame( { @@ -935,7 +517,6 @@ def test_bfllist(self, mapdl): } ) - self.solid_model(mapdl) mapdl.bfl(3, "TEMP", 15) bfllist_result = mapdl.bfllist().to_dataframe() @@ -944,7 +525,7 @@ def test_bfllist(self, mapdl): assert bfllist_result.compare(df_bfl).empty @requires("pandas") - def test_bfalist(self, mapdl): + def test_bfalist(self, mapdl, solid_model): df_bfa = pd.DataFrame( { @@ -954,7 +535,6 @@ def test_bfalist(self, mapdl): } ) - self.solid_model(mapdl) mapdl.bfa(1, "TEMP", 20) bfalist_result = mapdl.bfalist().to_dataframe() @@ -963,42 +543,11 @@ def test_bfalist(self, mapdl): assert bfalist_result.compare(df_bfa).empty -class Test_bc_cmdlist_model: - - def solid_model(self, mapdl): - # Solid model (Geometry) - - mapdl.clear() - - mapdl.prep7() - - # Define keypoints, lines and area - # -------------------- - mapdl.k(1, 0, 0) - mapdl.k(2, 1, 0) - mapdl.k(3, 1, 1) - mapdl.l(1, 2) - mapdl.l(2, 3) - mapdl.l(3, 1) - mapdl.a(1, 2, 3) - - # Define a material - # -------------------- - mapdl.mp("EX", 1, 30e6) - mapdl.mp("NUXY", 1, 0.25) # Poisson's Ratio - - # Define section - # -------------------- - mapdl.et(1, "PLANE183") - mapdl.keyopt(1, 1, 0) - mapdl.keyopt(1, 3, 3) - mapdl.keyopt(1, 6, 0) - mapdl.r(1, 0.01) +class Test_bc_cmdlist_model(TestClass): + @pytest.fixture(scope="class") def fe_model(self, mapdl): - # FE model (Mesh) - - self.solid_model(mapdl) + solid_FE_model(mapdl) mapdl.esize(0.02) mapdl.mshape(0, "2D") @@ -1006,7 +555,7 @@ def fe_model(self, mapdl): mapdl.amesh(1, 1, 1) @requires("pandas") - def test_dlist(self, mapdl): + def test_dlist(self, mapdl, fe_model): df_d = pd.DataFrame( { @@ -1017,7 +566,6 @@ def test_dlist(self, mapdl): } ) - self.fe_model(mapdl) mapdl.d(2, "UX", 0) mapdl.d(2, "UY", 0) @@ -1027,7 +575,7 @@ def test_dlist(self, mapdl): assert dlist_result.compare(df_d).empty @requires("pandas") - def test_flist(self, mapdl): + def test_flist(self, mapdl, fe_model): df_f = pd.DataFrame( { @@ -1038,7 +586,6 @@ def test_flist(self, mapdl): } ) - self.fe_model(mapdl) mapdl.f(4, "FX", 10) mapdl.f(4, "FY", 20) @@ -1048,7 +595,7 @@ def test_flist(self, mapdl): assert flist_result.compare(df_f).empty -class Test_MAPDL_commands: +class Test_MAPDL_commands(TestClass): SKIP = [ "aplot", "cfopen", @@ -1130,3 +677,41 @@ def test_command(self, mapdl, cmd): cmd_ = cmd_.replace("STAR", "*") assert cmd_ in post.upper() + + # Restoring defaults + if "show" in cmd: + mapdl.show("PNG") + + +class Test_output_listing(TestClass): + + @staticmethod + @pytest.fixture(scope="class") + def plastic_solve_output(mapdl): + mapdl.mute = True + mapdl.input(vmfiles["vm273"]) + + mapdl.post1() + mapdl.set(1, 2) + mapdl.mute = False + + @staticmethod + @pytest.mark.parametrize( + "func,args", + [("prnsol", ("U", "X")), ("presol", ("S", "X")), ("presol", ("S", "ALL"))], + ) + def test_output_listing(mapdl, plastic_solve_output, func, args): + mapdl.post1() + func_ = getattr(mapdl, func) + out = func_(*args) + + out_list = out.to_list() + out_array = out.to_array() + + assert isinstance(out, CommandListingOutput) + assert isinstance(out_list, list) and out_list + assert isinstance(out_array, np.ndarray) and out_array.size != 0 + + if has_dependency("pandas"): + out_df = out.to_dataframe() + assert isinstance(out_df, pd.DataFrame) and not out_df.empty diff --git a/tests/test_component.py b/tests/test_component.py index 976460aae5..6b2a293cde 100644 --- a/tests/test_component.py +++ b/tests/test_component.py @@ -108,12 +108,14 @@ def test_get_item_autoselect_components(mapdl, cube_geom_and_mesh): mapdl.components["mycomp"] = "node", [1, 2, 3] mapdl.cmsel("NONE") + prev = mapdl.components._autoselect_components mapdl.components._autoselect_components = True cm_ = mapdl.run("cmlist").upper() assert "MYCOMP" not in cm_ assert "NODE" not in cm_ assert mapdl.components["mycomp"] == (1, 2, 3) + mapdl.components._autoselect_components = prev def test_raise_empty_comp(mapdl, cleared): @@ -179,6 +181,9 @@ def test_default_entity(mapdl, cube_geom_and_mesh, type_): assert comp_name in cm_ assert type_.upper() in cm_ + # Returning back to default + mapdl.components.default_entity = "NODES" + @pytest.mark.parametrize( "func,entity,selector,imax", @@ -271,7 +276,7 @@ def test_default_entity_error(mapdl, cube_geom_and_mesh): mapdl.components.default_entity = "asdf" -def test_logger(mapdl): +def test_logger(mapdl, cleared): assert mapdl.components.logger == mapdl.logger diff --git a/tests/test_console.py b/tests/test_console.py index dcfe410f80..a8f598b348 100644 --- a/tests/test_console.py +++ b/tests/test_console.py @@ -68,16 +68,16 @@ def test_jobname(mapdl_console, cleared): assert mapdl_console.jobname == other_jobname -def test_empty(mapdl_console): +def test_empty(mapdl_console, cleared): with pytest.raises(ValueError): mapdl_console.run("") -def test_str(mapdl_console): +def test_str(mapdl_console, cleared): assert "ANSYS Mechanical" in str(mapdl_console) -def test_version(mapdl_console): +def test_version(mapdl_console, cleared): assert isinstance(mapdl_console.version, float) @@ -103,8 +103,7 @@ def test_basic_command(cleared, mapdl_console): assert "CREATE A HEXAHEDRAL VOLUME" in resp -def test_allow_ignore(mapdl_console): - mapdl_console.clear() +def test_allow_ignore(mapdl_console, cleared): mapdl_console.allow_ignore = False assert mapdl_console.allow_ignore is False with pytest.raises(pymapdl.errors.MapdlInvalidRoutineError): @@ -217,12 +216,12 @@ def test_al(cleared, mapdl_console): assert a0 == 1 -def test_invalid_area(mapdl_console): +def test_invalid_area(mapdl_console, cleared): with pytest.raises(MapdlRuntimeError): mapdl_console.a(0, 0, 0, 0) -# def test_invalid_input(mapdl_console): +# def test_invalid_input(mapdl_console, cleared): # with pytest.raises(FileNotFoundError): # mapdl_console.input('thisisnotafile') @@ -462,7 +461,7 @@ def test_elements(cleared, mapdl_console): np.random.random((10, 3, 3)), ), ) -def test_set_get_parameters(mapdl_console, parm): +def test_set_get_parameters(mapdl_console, cleared, parm): parm_name = pymapdl.misc.random_string(20) mapdl_console.parameters[parm_name] = parm if isinstance(parm, str): @@ -476,7 +475,7 @@ def test_set_parameters_arr_to_scalar(mapdl_console, cleared): mapdl_console.parameters["PARM"] = 2 -def test_set_parameters_string_spaces(mapdl_console): +def test_set_parameters_string_spaces(mapdl_console, cleared): with pytest.raises(ValueError): mapdl_console.parameters["PARM"] = "string with spaces" @@ -506,7 +505,7 @@ def test_builtin_parameters(mapdl_console, cleared): assert mapdl_console.parameters.real == 1 -def test_eplot_fail(mapdl_console): +def test_eplot_fail(mapdl_console, cleared): # must fail with empty mesh with pytest.raises(MapdlRuntimeError): mapdl_console.eplot() @@ -596,7 +595,7 @@ def test_cyclic_solve(mapdl_console, cleared): assert mapdl_console.result.nsets == 16 # multiple result files... -def test_load_table(mapdl_console): +def test_load_table(mapdl_console, cleared): my_conv = np.array( [ [0, 0.001], @@ -611,7 +610,7 @@ def test_load_table(mapdl_console): assert np.allclose(mapdl_console.parameters["my_conv"], my_conv[:, -1]) -def test_mode_console(mapdl_console): +def test_mode_console(mapdl_console, cleared): assert mapdl_console.mode == "console" assert not mapdl_console.is_grpc assert not mapdl_console.is_corba diff --git a/tests/test_database.py b/tests/test_database.py index 39417dd684..e051b72e20 100644 --- a/tests/test_database.py +++ b/tests/test_database.py @@ -30,7 +30,7 @@ from ansys.mapdl.core.database import MINIMUM_MAPDL_VERSION, DBDef, MapdlDb from ansys.mapdl.core.errors import MapdlRuntimeError, MapdlVersionError from ansys.mapdl.core.misc import random_string -from conftest import ON_CI +from conftest import ON_CI, TestClass @pytest.fixture(scope="session") @@ -65,7 +65,7 @@ def db(mapdl): return mapdl.db -def test_failure_on_non_allowed_versions(mapdl): +def test_failure_on_non_allowed_versions(mapdl, cleared): if str(mapdl.version) in ["24.1", "24.2"]: with pytest.raises(MapdlVersionError): mapdl.db.start() @@ -73,28 +73,7 @@ def test_failure_on_non_allowed_versions(mapdl): pytest.skip(f"Should run only on MAPDL 24.1 and 24.2") -@pytest.fixture(scope="session") -def gen_block(mapdl): - """Generate nodes and elements in a simple block.""" - mapdl.clear() - mapdl.prep7() - mapdl.block(0, 1, 0, 1, 0, 1) - mapdl.et(1, 186) - mapdl.esize(0.25) - mapdl.vmesh("ALL") - - -@pytest.fixture(scope="session") -def nodes(gen_block, db): - return db.nodes - - -@pytest.fixture(scope="session") -def elems(gen_block, db): - return db.elems - - -def test_database_start_stop(mapdl): +def test_database_start_stop(mapdl, cleared): if mapdl._server_version < (0, 4, 1): # 2021R2 pytest.skip("requires 2021R2 or newer") @@ -154,131 +133,6 @@ def test_clear(db): assert db._mapdl.get_value("KP", 0, "count") == 0.0 -def test_nodes_repr(nodes): - assert "425" in str(nodes) - assert "Number of nodes" in str(nodes) - - -def test_nodes_first(nodes): - assert nodes.first() == 1 - assert nodes.first(inod=10) == 11 - - -def test_nodes_next(nodes): - nodes._itnod = -1 # resets nodes state - - with pytest.raises( - MapdlRuntimeError, match="You first have to call the `DbNodes.first` method" - ): - nodes.next() - - nodes.first() - assert nodes.next() == 2 - - -def test_nodes_info(nodes): - assert nodes.info(1, DBDef.DB_SELECTED) == 1 - - -@pytest.mark.parametrize("selected", [True, False]) -def test_nodes_num(nodes, selected): - assert nodes.num(selected=selected) == 425 - - -def test_nodes_max_num(nodes): - assert nodes.max_num == 425 - - -def test_nodes_coord(nodes): - sel, coord = nodes.coord(22) - assert sel == 0 # selected - assert coord == (1.0, 0.5, 0.0, 0.0, 0.0, 0.0) - - -def test_nodes_asarray(nodes): - ind, coords, angles = nodes.all_asarray() - assert np.allclose(ind, np.arange(1, 426)) - - assert np.allclose(coords, nodes._db._mapdl.mesh.nodes) - assert np.allclose(angles, 0) - - -def test_nodes_push(nodes): - nnum = 100000 - x, y, z, xang, yang, zang = 1, 5, 10, 30, 40, 50 - nodes.push(nnum, x, y, z, xang, yang, zang) - - selected, coord = nodes.coord(nnum) - assert selected == 0 - assert coord == (x, y, z, xang, yang, zang) - - with pytest.raises(ValueError, match="X angle must be input"): - nodes.push(nnum, x, y, z, yang=1) - - with pytest.raises(ValueError, match="X and Y angles must be input"): - nodes.push(nnum, x, y, z, zang=1) - - -def test_elems_repr(elems): - assert "64" in str(elems) - assert "Number of elements" in str(elems) - - -def test_elems_first(elems): - assert elems.first() == 1 - assert elems.first(ielm=10) == 11 - - -def test_elems_next(elems): - elems._itelm = -1 # resets elems state - - with pytest.raises( - MapdlRuntimeError, match="You first have to call the `DbElems.first` method" - ): - elems.next() - - elems.first() - assert elems.next() == 2 - - -def test_elems_info(elems): - assert elems.info(1, DBDef.DB_SELECTED) == 1 - - -@pytest.mark.parametrize("selected", [True, False]) -def test_elems_num(elems, selected): - assert elems.num(selected=selected) == 64 - - -def test_elems_max_num(elems): - assert elems.max_num == 64 - - -def test_elems_get(elems): - ielm = 1 - elem_info = elems.get(ielm) - - assert len(elem_info.nodes) == elem_info.nnod - assert len(elem_info.elmdat) == 10 - assert elem_info.ielem == ielm - - -def test_elems_push(elems): - ielm = 1 - elem_info = elems.get(ielm) - - ielm_new = 10000 - elems.push(ielm_new, elem_info.elmdat, elem_info.nodes) - - elem_info_new = elems.get(ielm_new) - assert elem_info.elmdat == elem_info_new.elmdat - assert elem_info.nnod == elem_info_new.nnod - assert elem_info.nodes == elem_info_new.nodes - - with pytest.raises(ValueError, match="`elmdat` must be length 10"): - elems.push(ielm_new, [1, 2, 3], elem_info.nodes) - - def test__channel_str(db): assert db._channel_str is not None assert ":" in db._channel_str @@ -286,7 +140,7 @@ def test__channel_str(db): assert re.search("\d{4,6}", db._channel_str) -def test_off_db(mapdl, db): +def test_off_db(mapdl, cleared, db): """Testing that when there is no active database""" if db.active: db.stop() @@ -295,7 +149,7 @@ def test_off_db(mapdl, db): assert mapdl.db.elems is None -def test_wrong_api_version(mapdl, db): +def test_wrong_api_version(mapdl, cleared, db): mapdl.db.stop() mapdl.__server_version = (0, 1, 1) mapdl._MapdlGrpc__server_version = (0, 1, 1) @@ -314,7 +168,7 @@ def test_wrong_api_version(mapdl, db): assert "is currently running" in mapdl.db._status() -def test_repr(mapdl, db): +def test_repr(mapdl, cleared, db): elems = mapdl.db.elems nodes = mapdl.db.nodes @@ -326,3 +180,154 @@ def test_repr(mapdl, db): assert isinstance(elems.__str__(), str) assert isinstance(nodes.__str__(), str) + + +def gen_block(mapdl): + """Generate nodes and elements in a simple block.""" + mapdl.block(0, 1, 0, 1, 0, 1) + mapdl.et(1, 186) + mapdl.esize(0.25) + mapdl.vmesh("ALL") + + +class Test_Nodes(TestClass): + + @staticmethod + @pytest.fixture(scope="class") + def nodes(mapdl, db): + gen_block(mapdl) + return db.nodes + + @staticmethod + def test_nodes_repr(nodes): + assert "425" in str(nodes) + assert "Number of nodes" in str(nodes) + + @staticmethod + def test_nodes_first(nodes): + assert nodes.first() == 1 + assert nodes.first(inod=10) == 11 + + @staticmethod + def test_nodes_next(nodes): + nodes._itnod = -1 # resets nodes state + + with pytest.raises( + MapdlRuntimeError, match="You first have to call the `DbNodes.first` method" + ): + nodes.next() + + nodes.first() + assert nodes.next() == 2 + + @staticmethod + def test_nodes_info(nodes): + assert nodes.info(1, DBDef.DB_SELECTED) == 1 + + @pytest.mark.parametrize("selected", [True, False]) + @staticmethod + def test_nodes_num(nodes, selected): + assert nodes.num(selected=selected) == 425 + + @staticmethod + def test_nodes_max_num(nodes): + assert nodes.max_num == 425 + + @staticmethod + def test_nodes_coord(nodes): + sel, coord = nodes.coord(22) + assert sel == 0 # selected + assert coord == (1.0, 0.5, 0.0, 0.0, 0.0, 0.0) + + @staticmethod + def test_nodes_asarray(nodes): + ind, coords, angles = nodes.all_asarray() + assert np.allclose(ind, np.arange(1, 426)) + + assert np.allclose(coords, nodes._db._mapdl.mesh.nodes) + assert np.allclose(angles, 0) + + @staticmethod + def test_nodes_push(nodes): + nnum = 100000 + x, y, z, xang, yang, zang = 1, 5, 10, 30, 40, 50 + nodes.push(nnum, x, y, z, xang, yang, zang) + + selected, coord = nodes.coord(nnum) + assert selected == 0 + assert coord == (x, y, z, xang, yang, zang) + + with pytest.raises(ValueError, match="X angle must be input"): + nodes.push(nnum, x, y, z, yang=1) + + with pytest.raises(ValueError, match="X and Y angles must be input"): + nodes.push(nnum, x, y, z, zang=1) + + +class Test_Elems(TestClass): + + @staticmethod + @pytest.fixture(scope="class") + def elems(mapdl, db): + gen_block(mapdl) + return db.elems + + @staticmethod + def test_elems_repr(elems): + assert "64" in str(elems) + assert "Number of elements" in str(elems) + + @staticmethod + def test_elems_first(elems): + assert elems.first() == 1 + assert elems.first(ielm=10) == 11 + + @staticmethod + def test_elems_next(elems): + elems._itelm = -1 # resets elems state + + with pytest.raises( + MapdlRuntimeError, match="You first have to call the `DbElems.first` method" + ): + elems.next() + + elems.first() + assert elems.next() == 2 + + @staticmethod + def test_elems_info(elems): + assert elems.info(1, DBDef.DB_SELECTED) == 1 + + @pytest.mark.parametrize("selected", [True, False]) + @staticmethod + def test_elems_num(elems, selected): + assert elems.num(selected=selected) == 64 + + @staticmethod + def test_elems_max_num(elems): + assert elems.max_num == 64 + + @staticmethod + def test_elems_get(elems): + ielm = 1 + elem_info = elems.get(ielm) + + assert len(elem_info.nodes) == elem_info.nnod + assert len(elem_info.elmdat) == 10 + assert elem_info.ielem == ielm + + @staticmethod + def test_elems_push(elems): + ielm = 1 + elem_info = elems.get(ielm) + + ielm_new = 10000 + elems.push(ielm_new, elem_info.elmdat, elem_info.nodes) + + elem_info_new = elems.get(ielm_new) + assert elem_info.elmdat == elem_info_new.elmdat + assert elem_info.nnod == elem_info_new.nnod + assert elem_info.nodes == elem_info_new.nodes + + with pytest.raises(ValueError, match="`elmdat` must be length 10"): + elems.push(ielm_new, [1, 2, 3], elem_info.nodes) diff --git a/tests/test_element.py b/tests/test_element.py index 0758b69a63..9df3aa4d10 100644 --- a/tests/test_element.py +++ b/tests/test_element.py @@ -26,7 +26,7 @@ from ansys.mapdl.core import examples from ansys.mapdl.core._commands.parse import parse_e, parse_et -from conftest import requires +from conftest import TestClass, requires @pytest.fixture @@ -117,7 +117,7 @@ def test_etype(mapdl, cleared): assert "CURRENT NODAL DOF SET IS UX UY UZ" in out -def test_eshape(mapdl): +def test_eshape(mapdl, cleared): with pytest.warns(UserWarning): mapdl.eshape() @@ -138,7 +138,7 @@ def test_edele(mapdl, cleared): assert "DELETE SELECTED ELEMENTS" in output -class TestParseElementCommands: +class TestParseElementCommands(TestClass): @pytest.mark.parametrize( "message", [ diff --git a/tests/test_errors.py b/tests/test_errors.py index 80c51d7b0f..4cb65fdec5 100644 --- a/tests/test_errors.py +++ b/tests/test_errors.py @@ -102,7 +102,7 @@ ), ], ) -def test_raise_output_errors(mapdl, response, expected_error): +def test_raise_output_errors(mapdl, cleared, response, expected_error): if expected_error: with pytest.raises(expected_error): mapdl._raise_output_errors(response) @@ -134,7 +134,7 @@ def test_exception_classes(error_class): raise error_class(message) -def test_error_handler(mapdl): +def test_error_handler(mapdl, cleared): text = "is not a recognized" with pytest.raises(MapdlInvalidRoutineError, match="recognized"): mapdl._raise_errors(text) diff --git a/tests/test_geometry.py b/tests/test_geometry.py index 0ee6d6810a..9d69f86a90 100644 --- a/tests/test_geometry.py +++ b/tests/test_geometry.py @@ -209,15 +209,13 @@ def test_kdist(cleared, mapdl): # kept here for potential usage -# def test_kfill(cleared, mapdl): -# mapdl.clear() -# mapdl.prep7() -# kp0 = (0, 0, 0) -# kp1 = (10, 0, 0) +def test_kfill(cleared, mapdl): + kp0 = (0, 0, 0) + kp1 = (10, 0, 0) -# knum0 = mapdl.k("", *kp0) -# knum1 = mapdl.k("", *kp1) -# mapdl.kfill(knum0, knum1, 8, ninc=1) + knum0 = mapdl.k("", *kp0) + knum1 = mapdl.k("", *kp1) + mapdl.kfill(knum0, knum1, 8, ninc=1) def test_kl(cleared, mapdl): @@ -514,9 +512,7 @@ def test_ndist(cleared, mapdl): assert node_zdist == node2[2] - node1[2] -def test_empty_model(mapdl): - mapdl.clear() - +def test_empty_model(mapdl, cleared): assert mapdl.geometry.knum.size == 0 assert mapdl.geometry.lnum.size == 0 assert mapdl.geometry.anum.size == 0 @@ -543,7 +539,7 @@ def test_entities_multiple_bodies(mapdl, contact_geom_and_mesh, entity, number): assert isinstance(entity, pv.MultiBlock) -def test_create_geometry(mapdl): +def test_create_geometry(mapdl, cleared): assert isinstance(mapdl._create_geometry(), Geometry) diff --git a/tests/test_grpc.py b/tests/test_grpc.py index 8c7d0c3457..fd2454a4d0 100644 --- a/tests/test_grpc.py +++ b/tests/test_grpc.py @@ -73,7 +73,6 @@ def write_tmp_in_mapdl_instance(mapdl, filename, ext="txt"): @pytest.fixture(scope="function") def setup_for_cmatrix(mapdl, cleared): - mapdl.prep7() mapdl.title("Capacitance of two long cylinders above a ground plane") mapdl.run("a=100") # Cylinder inside radius (μm) mapdl.run("d=400") # Outer radius of air region @@ -118,7 +117,7 @@ def setup_for_cmatrix(mapdl, cleared): @pytest.fixture(scope="function") -def grpc_channel(mapdl): +def grpc_channel(mapdl, cleared): channel = grpc.insecure_channel( mapdl._channel_str, options=[ @@ -134,7 +133,7 @@ def test_connect_via_channel(grpc_channel): assert mapdl.is_alive -def test_clear_nostart(mapdl): +def test_clear_nostart(mapdl, cleared): resp = mapdl._send_command("FINISH") resp = mapdl._send_command("/CLEAR, NOSTART") assert re.search("CLEAR (ANSYS|MAPDL) DATABASE AND RESTART", resp) @@ -142,20 +141,20 @@ def test_clear_nostart(mapdl): # NOTE: This command cannot be run repeately, otherwise we end up with # to many levels of /INPUT. 2021R2 should have a fix for this -def test_clear(mapdl): +def test_clear(mapdl, cleared): resp = mapdl._send_command("FINISH") resp = mapdl._send_command("/CLEAR") assert "CLEAR" in resp -def test_clear_multiple(mapdl): +def test_clear_multiple(mapdl, cleared): # simply should not fail. See: # https://github.com/ansys/pymapdl/issues/380 for i in range(20): mapdl.run("/CLEAR") -def test_invalid_get_bug(mapdl): +def test_invalid_get_bug(mapdl, cleared): # versions before 24.1 should raise an error if mapdl.version < 24.1: context = pytest.raises(MapdlCommandIgnoredError) @@ -166,19 +165,17 @@ def test_invalid_get_bug(mapdl): mapdl.get_value("ACTIVE", item1="SET", it1num="invalid") -def test_invalid_get(mapdl): +def test_invalid_get(mapdl, cleared): with pytest.raises((MapdlRuntimeError, MapdlCommandIgnoredError)): mapdl.get_value("ACTIVE") -def test_stream(mapdl): +def test_stream(mapdl, cleared): resp = mapdl._send_command_stream("/PREP7") assert "PREP7" in resp -def test_basic_input_output(mapdl, tmpdir): - mapdl.finish() - mapdl.clear("NOSTART") +def test_basic_input_output(mapdl, tmpdir, cleared): filename = "tmp2.inp" basic_inp = tmpdir.join(filename) with open(basic_inp, "w") as f: @@ -196,9 +193,7 @@ def test_basic_input_output(mapdl, tmpdir): # input file won't actually run, but we want to see if the output switches -def test_upload_large(mapdl): - mapdl.finish() - mapdl.clear("NOSTART") +def test_upload_large(mapdl, cleared): file_name = examples.vmfiles["vm153"] test_file = os.path.join(PATH, "test_files", file_name) @@ -207,17 +202,17 @@ def test_upload_large(mapdl): assert os.path.basename(file_name) in mapdl.list_files() -def test_upload_fail(mapdl): +def test_upload_fail(mapdl, cleared): with pytest.raises(FileNotFoundError): mapdl.upload("thisisnotafile") -def test_input_empty(mapdl): +def test_input_empty(mapdl, cleared): resp = mapdl._send_command("/INPUT") assert "INPUT FILE" in resp -def test_input_empty(mapdl): +def test_input_not_a_file(mapdl, cleared): resp = mapdl._send_command("/INPUT, not_a_file") assert "does not exist" in resp @@ -233,7 +228,7 @@ def test_large_output(mapdl, cleared): assert sys.getsizeof(msg) > 4 * 1024**2 -def test__download_missing_file(mapdl, tmpdir): +def test__download_missing_file(mapdl, cleared, tmpdir): target = tmpdir.join("tmp") with pytest.raises(FileNotFoundError): mapdl.download("__notafile__", target) @@ -263,19 +258,15 @@ def test_cmatrix(mapdl, setup_for_cmatrix): # directory. -def test_read_input_file_verbose(mapdl): +def test_read_input_file_verbose(mapdl, cleared): test_file = examples.vmfiles["vm153"] - mapdl.finish() - mapdl.clear() response = mapdl.input(test_file, verbose=True) assert re.search("\*\*\*\*\* (ANSYS|MAPDL) SOLUTION ROUTINE \*\*\*\*\*", response) @pytest.mark.parametrize("file_name", ["full26.dat", "static.dat"]) -def test_read_input_file(mapdl, file_name): +def test_read_input_file(mapdl, file_name, cleared): test_file = os.path.join(PATH, "test_files", file_name) - mapdl.finish() - mapdl.clear() response = mapdl.input(test_file) assert ( @@ -284,13 +275,13 @@ def test_read_input_file(mapdl, file_name): ) -def test_no_get_value_non_interactive(mapdl): +def test_no_get_value_non_interactive(mapdl, cleared): with pytest.raises((MapdlRuntimeError, MapdlCommandIgnoredError)): with mapdl.non_interactive: mapdl.get_value("ACTIVE", item1="CSYS") -def test__download(mapdl, tmpdir): +def test__download(mapdl, cleared, tmpdir): # Creating temp file write_tmp_in_mapdl_instance(mapdl, "myfile0") @@ -325,7 +316,7 @@ def test__download(mapdl, tmpdir): ["myfile*", ["myfile0.txt", "myfile1.txt"]], ], ) -def test_download(mapdl, tmpdir, files_to_download, expected_output): +def test_download(mapdl, cleared, tmpdir, files_to_download, expected_output): write_tmp_in_mapdl_instance(mapdl, "myfile0") write_tmp_in_mapdl_instance(mapdl, "myfile1") @@ -348,7 +339,9 @@ def test_download(mapdl, tmpdir, files_to_download, expected_output): ["myfile*", ["myfile0.txt", "myfile1.txt"]], ], ) -def test_download_without_target_dir(mapdl, files_to_download, expected_output): +def test_download_without_target_dir( + mapdl, cleared, files_to_download, expected_output +): write_tmp_in_mapdl_instance(mapdl, "myfile0") write_tmp_in_mapdl_instance(mapdl, "myfile1") @@ -373,7 +366,7 @@ def test_download_without_target_dir(mapdl, files_to_download, expected_output): ], ) def test_download_with_extension( - mapdl, extension_to_download, files_to_download, expected_output + mapdl, cleared, extension_to_download, files_to_download, expected_output ): write_tmp_in_mapdl_instance(mapdl, "myfile0") write_tmp_in_mapdl_instance(mapdl, "myfile1") @@ -403,7 +396,7 @@ def test_download_with_extension( @requires("local") -def test_download_recursive(mapdl): +def test_download_recursive(mapdl, cleared): if mapdl.is_local: temp_dir = os.path.join(mapdl.directory, "new_folder") os.makedirs(temp_dir, exist_ok=True) @@ -425,7 +418,7 @@ def test_download_recursive(mapdl): shutil.rmtree("new_dir") -def test_download_project(mapdl, tmpdir): +def test_download_project(mapdl, cleared, tmpdir): target_dir = tmpdir.mkdir("tmp") mapdl.download_project(target_dir=target_dir) files_extensions = list( @@ -434,7 +427,7 @@ def test_download_project(mapdl, tmpdir): assert "log" in files_extensions -def test_download_project_extensions(mapdl, tmpdir): +def test_download_project_extensions(mapdl, cleared, tmpdir): target_dir = tmpdir.mkdir("tmp") mapdl.download_project(extensions=["log", "err"], target_dir=target_dir) files_extensions = set([each.split(".")[-1] for each in os.listdir(target_dir)]) @@ -467,21 +460,21 @@ def test_download_result(mapdl, cleared, tmpdir): pass -def test__channel_str(mapdl): +def test__channel_str(mapdl, cleared): assert mapdl._channel_str is not None assert ":" in mapdl._channel_str assert re.search("\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}", mapdl._channel_str) assert re.search("\d{4,6}", mapdl._channel_str) -def test_mode(mapdl): +def test_mode(mapdl, cleared): assert mapdl.connection == "grpc" assert mapdl.is_grpc assert not mapdl.is_corba assert not mapdl.is_console -def test_input_output(mapdl): +def test_input_output(mapdl, cleared): file_ = "myinput.inp" with open(file_, "w") as fid: for i in range(4): @@ -495,7 +488,7 @@ def test_input_output(mapdl): os.remove(file_) -def test_input_ext_argument(mapdl): +def test_input_ext_argument(mapdl, cleared): file_ = "myinput.inp" with open(file_, "w") as fid: for i in range(4): @@ -511,7 +504,7 @@ def test_input_ext_argument(mapdl): os.remove(file_) -def test_input_dir_argument(mapdl, tmpdir): +def test_input_dir_argument(mapdl, cleared, tmpdir): file_ = "myinput.inp" target_dir = str(tmpdir.mkdir(f"tmp_{random_string()}")) file_path = os.path.join(target_dir, file_) @@ -529,7 +522,7 @@ def test_input_dir_argument(mapdl, tmpdir): os.remove(file_path) -def test_input_line_argument(mapdl): +def test_input_line_argument(mapdl, cleared): file_ = "myinput.inp" with open(file_, "w") as fid: for i in range(4): @@ -545,7 +538,7 @@ def test_input_line_argument(mapdl): os.remove(file_) -def test_input_multiple_argument(mapdl, tmpdir): +def test_input_multiple_argument(mapdl, cleared, tmpdir): file_ = "myinput.inp" target_dir = str(tmpdir.mkdir(f"tmp_{random_string()}")) file_path = os.path.join(target_dir, file_) @@ -563,12 +556,12 @@ def test_input_multiple_argument(mapdl, tmpdir): os.remove(file_path) -def test_input_log_argument(mapdl): +def test_input_log_argument(mapdl, cleared): with pytest.raises(ValueError, match="'log' argument is not supported"): mapdl.input(log="asdf") -def test_input_compatibility_api_change(mapdl): +def test_input_compatibility_api_change(mapdl, cleared): """This test is because the API change happened in 0.65 to homogenise the APDL command with the gRPC method.""" @@ -584,7 +577,7 @@ def test_input_compatibility_api_change(mapdl): @requires("grpc") @requires("local") -def test__check_stds(mapdl): +def test__check_stds(mapdl, cleared): """Test that the standard input is checked.""" mapdl._read_stds() @@ -592,7 +585,7 @@ def test__check_stds(mapdl): assert mapdl._stderr is not None -def test_subscribe_to_channel(mapdl): +def test_subscribe_to_channel(mapdl, cleared): assert mapdl.channel_state in [ "IDLE", "CONNECTING", @@ -610,7 +603,7 @@ def test_subscribe_to_channel(mapdl): @requires("remote") -def test_exception_message_length(mapdl): +def test_exception_message_length(mapdl, cleared): # This test does not fail if running on local channel = grpc.insecure_channel( mapdl._channel_str, diff --git a/tests/test_information.py b/tests/test_information.py index 25ca76d4d5..8d2f5cfebf 100644 --- a/tests/test_information.py +++ b/tests/test_information.py @@ -27,7 +27,7 @@ import pytest -def test_mapdl_info(mapdl, capfd): +def test_mapdl_info(mapdl, cleared, capfd): info = mapdl.info for attr, value in inspect.getmembers(info): if not attr.startswith("_") and attr not in ["title", "stitles"]: @@ -45,13 +45,13 @@ def test_mapdl_info(mapdl, capfd): assert "UPDATE" in out -def test_info_title(mapdl): +def test_info_title(mapdl, cleared): title = "this is my title" mapdl.info.title = title assert title == mapdl.info.title -def test_info_stitle(mapdl): +def test_info_stitle(mapdl, cleared): info = mapdl.info assert all([not each for each in info.stitles]) diff --git a/tests/test_inline_functions/test_component_queries.py b/tests/test_inline_functions/test_component_queries.py index d06100a81b..212e835049 100644 --- a/tests/test_inline_functions/test_component_queries.py +++ b/tests/test_inline_functions/test_component_queries.py @@ -22,16 +22,13 @@ import pytest -from conftest import create_geometry, get_details_of_nodes +from conftest import TestClass, create_geometry, get_details_of_nodes -class TestCentroidGetter: +class TestCentroidGetter(TestClass): @pytest.fixture(scope="class") def box_geometry(self, mapdl): - mapdl.finish(mute=True) - mapdl.clear("NOSTART", mute=True) - mapdl.prep7(mute=True) areas, keypoints = create_geometry(mapdl) q = mapdl.queries return q, keypoints, areas, get_details_of_nodes(mapdl) @@ -101,15 +98,11 @@ def test_inverse_get_keypoints_at_coordinates(self, box_geometry, coords): assert kp in kps -class TestDisplacementComponentQueriesBox: +class TestDisplacementComponentQueriesBox(TestClass): @pytest.fixture(scope="class") def solved_box(self, mapdl): mapdl.mute = True # improve stability - mapdl.finish(mute=True) - mapdl.clear("NOSTART", mute=True) - - mapdl.prep7() mapdl.et(1, "SOLID5") mapdl.block(0, 10, 0, 20, 0, 30) mapdl.esize(10) @@ -152,14 +145,10 @@ def test_uz(self, solved_box): assert len(displaced_nodes) > 0 -class TestDisplacementComponentQueriesSheet: +class TestDisplacementComponentQueriesSheet(TestClass): @pytest.fixture(scope="class") def twisted_sheet(self, mapdl): - mapdl.finish(mute=True) - mapdl.clear("NOSTART", mute=True) - - mapdl.prep7() mapdl.et(1, "SHELL181") mapdl.mp("EX", 1, 2e5) mapdl.mp("PRXY", 1, 0.3) # Poisson's Ratio diff --git a/tests/test_inline_functions/test_connectivity_queries.py b/tests/test_inline_functions/test_connectivity_queries.py index 0831fd3d9c..3f638e08ef 100644 --- a/tests/test_inline_functions/test_connectivity_queries.py +++ b/tests/test_inline_functions/test_connectivity_queries.py @@ -22,16 +22,13 @@ import pytest -from conftest import create_geometry, get_details_of_nodes +from conftest import TestClass, create_geometry, get_details_of_nodes -class TestConnectivityQueries: +class TestConnectivityQueries(TestClass): - @pytest.fixture(scope="function") + @pytest.fixture(scope="class") def box_geometry(self, mapdl): - mapdl.finish(mute=True) - mapdl.clear("NOSTART", mute=True) - mapdl.prep7(mute=True) areas, keypoints = create_geometry(mapdl) q = mapdl.queries return q, keypoints, areas, get_details_of_nodes(mapdl) diff --git a/tests/test_inline_functions/test_field_component_queries.py b/tests/test_inline_functions/test_field_component_queries.py index 69b7913851..f67606d5bf 100644 --- a/tests/test_inline_functions/test_field_component_queries.py +++ b/tests/test_inline_functions/test_field_component_queries.py @@ -22,16 +22,14 @@ import pytest +from conftest import TestClass -class TestFieldComponentValueGetter: + +class TestFieldComponentValueGetter(TestClass): # The tests change the mesh so this fixture must be function scoped. - @pytest.fixture(scope="function") + @pytest.fixture(scope="class") def box_with_fields(self, mapdl): - mapdl.finish(mute=True) - mapdl.clear("NOSTART", mute=True) - - mapdl.prep7() mapdl.mp("kxx", 1, 45) mapdl.mp("ex", 1, 2e10) mapdl.mp("perx", 1, 1) @@ -47,11 +45,17 @@ def box_with_fields(self, mapdl): mapdl.et(4, "SOLID96") mapdl.block(0, 1, 0, 1, 0, 1) mapdl.esize(0.5) - return mapdl - def test_temp(self, box_with_fields): - mapdl = box_with_fields + mapdl.save("box_with_fields") + + @staticmethod + @pytest.fixture(scope="function") + def resume(mapdl, box_with_fields): mapdl.prep7() + mapdl.resume("box_with_fields") + mapdl.prep7() + + def test_temp(self, mapdl, resume): mapdl.type(1) mapdl.vmesh(1) mapdl.d("all", "temp", 5.0) @@ -60,9 +64,7 @@ def test_temp(self, box_with_fields): temp_value = mapdl.queries.temp(1) assert temp_value == 5.0 - def test_pressure(self, box_with_fields): - mapdl = box_with_fields - mapdl.prep7() + def test_pressure(self, mapdl, resume): mapdl.type(2) mapdl.vmesh(1) mapdl.d("all", "pres", 5.0) @@ -72,9 +74,7 @@ def test_pressure(self, box_with_fields): pres_value = mapdl.queries.pres(1) assert pres_value == 5.0 - def test_volt(self, box_with_fields): - mapdl = box_with_fields - mapdl.prep7() + def test_volt(self, mapdl, resume): mapdl.type(3) mapdl.vmesh(1) mapdl.d("all", "volt", 5.0) @@ -83,9 +83,7 @@ def test_volt(self, box_with_fields): volt_value = mapdl.queries.volt(1) assert volt_value == 5.0 - def test_mag(self, box_with_fields): - mapdl = box_with_fields - mapdl.prep7() + def test_mag(self, mapdl, resume): mapdl.type(4) mapdl.vmesh(1) mapdl.d("all", "mag", 5.0) diff --git a/tests/test_inline_functions/test_line_component_queries.py b/tests/test_inline_functions/test_line_component_queries.py index e6250ab918..f3719f23e9 100644 --- a/tests/test_inline_functions/test_line_component_queries.py +++ b/tests/test_inline_functions/test_line_component_queries.py @@ -24,15 +24,13 @@ import pytest +from conftest import TestClass -class TestLineCoordinateQueries: + +class TestLineCoordinateQueries(TestClass): @pytest.fixture(scope="class") def line_geometry(self, mapdl): - mapdl.finish(mute=True) - mapdl.clear("NOSTART", mute=True) - - mapdl.prep7(mute=True) k0 = mapdl.k(1, 0, 0, 0) k1 = mapdl.k(2, 1, 2, 2) l0 = mapdl.l(k0, k1) @@ -55,13 +53,9 @@ def test_lz(self, line_geometry): assert z == 1.0 -class TestLineSlopeQueries: +class TestLineSlopeQueries(TestClass): @pytest.fixture(scope="class") def line_geometry(self, mapdl): - mapdl.finish(mute=True) - mapdl.clear("NOSTART", mute=True) - - mapdl.prep7(mute=True) k0 = mapdl.k(1, 0, 0, 0) k1 = mapdl.k(2, 1, 2, 2) l0 = mapdl.l(k0, k1) diff --git a/tests/test_inline_functions/test_nearest_queries.py b/tests/test_inline_functions/test_nearest_queries.py index 8b935d64ba..4b0b69fec0 100644 --- a/tests/test_inline_functions/test_nearest_queries.py +++ b/tests/test_inline_functions/test_nearest_queries.py @@ -22,17 +22,13 @@ import pytest -from conftest import create_geometry, get_details_of_nodes +from conftest import TestClass, create_geometry, get_details_of_nodes -class TestNearestEntityQueries: +class TestNearestEntityQueries(TestClass): @pytest.fixture(scope="class") def box_geometry(self, mapdl): - mapdl.finish(mute=True) - mapdl.clear("NOSTART", mute=True) - mapdl.prep7(mute=True) - areas, keypoints = create_geometry(mapdl) q = mapdl.queries return q, keypoints, areas, get_details_of_nodes(mapdl) diff --git a/tests/test_inline_functions/test_normals_queries.py b/tests/test_inline_functions/test_normals_queries.py index f86cc8bde2..3cf7a453d8 100644 --- a/tests/test_inline_functions/test_normals_queries.py +++ b/tests/test_inline_functions/test_normals_queries.py @@ -20,8 +20,10 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. +from conftest import TestClass -class TestNormalsNodeQueries: + +class TestNormalsNodeQueries(TestClass): @staticmethod def build_plane(mapdl, plane: str): n1 = mapdl.n(1, 0, 0, 0) @@ -52,7 +54,7 @@ def test_normnz(self, query): assert abs(cosine) == 1.0 -class TestNormalsKeypointsQueries: +class TestNormalsKeypointsQueries(TestClass): @staticmethod def build_plane(mapdl, plane: str): k1 = mapdl.k(1, 0, 0, 0) diff --git a/tests/test_inline_functions/test_query.py b/tests/test_inline_functions/test_query.py index c24f6ad327..442e9ecf18 100644 --- a/tests/test_inline_functions/test_query.py +++ b/tests/test_inline_functions/test_query.py @@ -23,7 +23,7 @@ import pytest from ansys.mapdl.core.errors import MapdlCommandIgnoredError, MapdlRuntimeError -from conftest import requires +from conftest import TestClass, requires class TestParseParameter: @@ -84,14 +84,10 @@ def test_parse_int_type_error(self, value, query): query._parse_parameter_integer_response(input_) -class TestRunQuery: +class TestRunQuery(TestClass): @pytest.fixture(scope="class") def line_geometry(self, mapdl): - mapdl.finish(mute=True) - mapdl.clear("NOSTART", mute=True) - - mapdl.prep7(mute=True) k0 = mapdl.k(1, 0, 0, 0) k1 = mapdl.k(2, 1, 2, 2) l0 = mapdl.l(k0, k1) diff --git a/tests/test_inline_functions/test_selection_queries.py b/tests/test_inline_functions/test_selection_queries.py index 7708d44ce2..7a754fc666 100644 --- a/tests/test_inline_functions/test_selection_queries.py +++ b/tests/test_inline_functions/test_selection_queries.py @@ -23,6 +23,7 @@ import pytest from ansys.mapdl.core.inline_functions import SelectionStatus +from conftest import TestClass class TestSelectionStatus: @@ -38,7 +39,24 @@ def test_unhappy(self, value): SelectionStatus(value) -class TestNSEL: +class TestXSEL(TestClass): + + @staticmethod + @pytest.fixture(scope="class") + def selection_test_geometry(mapdl): + k0 = mapdl.k(1, 0, 0, 0) + k1 = mapdl.k(2, 0, 0, 1) + k2 = mapdl.k(3, 0, 1, 0) + k3 = mapdl.k(4, 1, 0, 0) + mapdl.v(k0, k1, k2, k3) + mapdl.mshape(1, "3D") + mapdl.et(1, "SOLID98") + mapdl.esize(0.5) + mapdl.vmesh("ALL") + return mapdl.queries + + +class TestNSEL(TestXSEL): def test_selected(self, selection_test_geometry): q = selection_test_geometry q._mapdl.nsel("S", "LOC", "X", 0) @@ -59,7 +77,7 @@ def test_undefined(self, selection_test_geometry): assert select == 0 -class TestKSEL: +class TestKSEL(TestXSEL): def test_selected(self, selection_test_geometry): q = selection_test_geometry q._mapdl.ksel("S", "LOC", "X", 0) @@ -80,7 +98,7 @@ def test_undefined(self, selection_test_geometry): assert select == 0 -class TestLSEL: +class TestLSEL(TestXSEL): def test_selected(self, selection_test_geometry): q = selection_test_geometry q._mapdl.lsel("all") @@ -102,7 +120,7 @@ def test_undefined(self, selection_test_geometry): assert select == 0 -class TestASEL: +class TestASEL(TestXSEL): def test_selected(self, selection_test_geometry): q = selection_test_geometry q._mapdl.asel("all") @@ -124,7 +142,7 @@ def test_undefined(self, selection_test_geometry): assert select == 0 -class TestESEL: +class TestESEL(TestXSEL): def test_selected(self, selection_test_geometry): q = selection_test_geometry q._mapdl.esel("all") @@ -146,7 +164,7 @@ def test_undefined(self, selection_test_geometry): assert select == 0 -class TestVSEL: +class TestVSEL(TestXSEL): def test_selected(self, selection_test_geometry): q = selection_test_geometry q._mapdl.vsel("all") @@ -165,7 +183,7 @@ def test_undefined(self, selection_test_geometry): assert select == 0 -class TestNDNEXT: +class TestNDNEXT(TestXSEL): def test_existing_nodes( self, selection_test_geometry, common_functions_and_classes ): @@ -201,7 +219,7 @@ def test_non_existing_nodes(self, selection_test_geometry): assert next_ == 0 -class TestELNEXT: +class TestELNEXT(TestXSEL): def test_existing_elements( self, selection_test_geometry, common_functions_and_classes ): @@ -237,7 +255,7 @@ def test_non_existing_elements(self, selection_test_geometry): assert next_ == 0 -class TestKPNEXT: +class TestKPNEXT(TestXSEL): def test_existing_kps(self, selection_test_geometry): q = selection_test_geometry next_ = q.kpnext(1) @@ -254,7 +272,7 @@ def test_non_existing_kps(self, selection_test_geometry): assert next_ == 0 -class TestLSNEXT: +class TestLSNEXT(TestXSEL): def test_existing_lines(self, selection_test_geometry): # there are 6 lines in in the selection_test_geometry fixture q = selection_test_geometry @@ -272,7 +290,7 @@ def test_non_existing_lines(self, selection_test_geometry): assert next_ == 0 -class TestARNEXT: +class TestARNEXT(TestXSEL): def test_existing_areas(self, selection_test_geometry): # there are 4 areas in in the selection_test_geometry fixture q = selection_test_geometry @@ -290,10 +308,9 @@ def test_non_existing_areas(self, selection_test_geometry): assert next_ == 0 -class TestVLNEXT: +class TestVLNEXT(TestXSEL): @staticmethod def make_volumes(mapdl): - mapdl.prep7() point1 = mapdl.k(999, 0, 10, 0) point2 = mapdl.k(99, 0, 0, 10) kps = [mapdl.k(i + 1, i, 0, 0) for i in range(10)] diff --git a/tests/test_krylov.py b/tests/test_krylov.py index 066dc6ba1f..cab575a733 100644 --- a/tests/test_krylov.py +++ b/tests/test_krylov.py @@ -111,12 +111,11 @@ def solu_krylov(mapdl, frq): mapdl.finish() -def test_krylov_with_point_load(mapdl): +def test_krylov_with_point_load(mapdl, cleared): if not server_meets_version(mapdl._server_version, (0, 5, 0)): pytest.skip("Requires MAPDL 2022 R2 or later.") # Case1 : Run Krylov PyMAPDL - mapdl.clear() mapdl.jobname = "point_load_py" # Parameters set for Krylov @@ -143,13 +142,12 @@ def test_krylov_with_point_load(mapdl): @pytest.mark.parametrize( "residual_algorithm", ["L-inf", "Linf", "L-1", "L1", "L-2", "L2"] ) -def test_krylov_with_pressure_load(mapdl, residual_algorithm): +def test_krylov_with_pressure_load(mapdl, cleared, residual_algorithm): if not server_meets_version(mapdl._server_version, (0, 5, 0)): pytest.skip("Requires MAPDL 2022 R2 or later.") # With ramped loading # Case1 : Run Krylov PyMAPDL - mapdl.clear() mapdl.jobname = "pressure_py" # Parameters set for Krylov diff --git a/tests/test_launcher.py b/tests/test_launcher.py index eca73fb9a5..15e1b07958 100644 --- a/tests/test_launcher.py +++ b/tests/test_launcher.py @@ -192,7 +192,7 @@ def test_find_mapdl_linux(): @requires("ansys-tools-path") @requires("local") -def test_invalid_mode(mapdl): +def test_invalid_mode(mapdl, cleared): with pytest.raises(ValueError): exec_file = find_mapdl(installed_mapdl_versions[0])[0] pymapdl.launch_mapdl( @@ -203,7 +203,7 @@ def test_invalid_mode(mapdl): @requires("ansys-tools-path") @requires("local") @pytest.mark.skipif(not os.path.isfile(V150_EXEC), reason="Requires v150") -def test_old_version(mapdl): +def test_old_version(mapdl, cleared): exec_file = find_mapdl("150")[0] with pytest.raises(ValueError): pymapdl.launch_mapdl( @@ -236,7 +236,7 @@ def test_launch_console(version): @requires("nostudent") @requires("ansys-tools-path") @pytest.mark.parametrize("license_name", LICENSES) -def test_license_type_keyword_names(mapdl, monkeypatch, license_name): +def test_license_type_keyword_names(monkeypatch, license_name): exec_file = find_mapdl()[0] args = launch_mapdl( exec_file=exec_file, license_type=license_name, _debug_no_launch=True @@ -246,7 +246,7 @@ def test_license_type_keyword_names(mapdl, monkeypatch, license_name): # @requires("local") @pytest.mark.parametrize("license_name", LICENSES) -def test_license_type_additional_switch(mapdl, license_name): +def test_license_type_additional_switch(license_name): args = launch_mapdl( additional_switches=QUICK_LAUNCH_SWITCHES + " -p " + license_name, _debug_no_launch=True, @@ -256,7 +256,7 @@ def test_license_type_additional_switch(mapdl, license_name): @stack(*PATCH_MAPDL_START) @requires("ansys-tools-path") -def test_license_type_dummy(mapdl): +def test_license_type_dummy(mapdl, cleared): dummy_license_type = "dummy" with pytest.warns( UserWarning, @@ -273,7 +273,7 @@ def test_license_type_dummy(mapdl): @requires("local") @requires("nostudent") -def test_remove_temp_dir_on_exit(mapdl): +def test_remove_temp_dir_on_exit(mapdl, cleared): """Ensure the working directory is removed when run_location is not set.""" mapdl_ = launch_mapdl( port=mapdl.port + 1, @@ -296,7 +296,7 @@ def test_remove_temp_dir_on_exit(mapdl): @requires("local") @requires("nostudent") -def test_remove_temp_dir_on_exit_fail(tmpdir, mapdl): +def test_remove_temp_dir_on_exit_fail(mapdl, cleared, tmpdir): """Ensure the working directory is not removed when the cwd is changed.""" mapdl_ = launch_mapdl( port=mapdl.port + 1, @@ -448,7 +448,7 @@ def test__verify_version_latest(): @requires("ansys-tools-path") @requires("local") -def test_find_mapdl(mapdl): +def test_find_ansys(mapdl, cleared): assert find_mapdl() is not None # Checking ints @@ -466,7 +466,7 @@ def test_find_mapdl(mapdl): @requires("local") -def test_version(mapdl): +def test_version(mapdl, cleared): version = int(10 * mapdl.version) launching_arg = launch_mapdl( port=mapdl.port + 1, @@ -479,7 +479,7 @@ def test_version(mapdl): @requires("local") -def test_raise_exec_path_and_version_launcher(mapdl): +def test_raise_exec_path_and_version_launcher(mapdl, cleared): with pytest.raises(ValueError): get_version("asdf", "asdf") @@ -496,7 +496,7 @@ def test_get_default_ansys(): assert get_default_ansys() is not None -def test_launch_mapdl_non_recognaised_arguments(mapdl): +def test_launch_mapdl_non_recognaised_arguments(mapdl, cleared): with pytest.raises(ValueError, match="my_fake_argument"): launch_mapdl( port=mapdl.port + 1, @@ -525,7 +525,7 @@ def test__parse_ip_route(): assert "172.23.112.1" == _parse_ip_route(output) -def test_launched(mapdl): +def test_launched(mapdl, cleared): if ON_LOCAL: assert mapdl.launched else: @@ -533,7 +533,7 @@ def test_launched(mapdl): @requires("local") -def test_launching_on_busy_port(mapdl, monkeypatch): +def test_launching_on_busy_port(mapdl, cleared, monkeypatch): monkeypatch.delenv("PYMAPDL_PORT", raising=False) with pytest.raises(PortAlreadyInUseByAnMAPDLInstance): launch_mapdl(port=mapdl.port) @@ -1324,7 +1324,7 @@ def test_check_mapdl_launch_on_hpc(message_stdout, message_stderr): @patch("ansys.mapdl.core.Mapdl._exit_mapdl", lambda *args, **kwargs: None) @patch("ansys.mapdl.core.mapdl_grpc.MapdlGrpc.kill_job") -def test_exit_job(mock_popen, mapdl): +def test_exit_job(mock_popen, mapdl, cleared): # Setting to exit mapdl._mapdl_on_hpc = True mapdl.finish_job_on_exit = True @@ -1589,7 +1589,7 @@ def test_get_ip(monkeypatch, ip, ip_env): "port,port_envvar,start_instance,port_busy,result", ( [None, None, True, False, 50052], # Standard case - [None, None, True, True, 50055], # Busy port case, not sure why it is not 50054 + [None, None, True, True, 50054], [None, 50053, True, True, 50053], [None, 50053, False, False, 50053], [50054, 50053, True, False, 50054], @@ -1597,9 +1597,10 @@ def test_get_ip(monkeypatch, ip, ip_env): [50054, None, False, False, 50054], ), ) -@patch("ansys.mapdl.core._LOCAL_PORTS", []) def test_get_port(monkeypatch, port, port_envvar, start_instance, port_busy, result): # Settings + pymapdl._LOCAL_PORTS = [] # Resetting + monkeypatch.delenv("PYMAPDL_PORT", False) if port_envvar: monkeypatch.setenv("PYMAPDL_PORT", port_envvar) diff --git a/tests/test_launcher_remote.py b/tests/test_launcher_remote.py index 5b13afed37..f653f78fb4 100644 --- a/tests/test_launcher_remote.py +++ b/tests/test_launcher_remote.py @@ -38,7 +38,7 @@ from conftest import QUICK_LAUNCH_SWITCHES -def test_launch_remote_instance(monkeypatch, mapdl): +def test_launch_remote_instance(mapdl, cleared, monkeypatch): # Create a mock pypim pretenting it is configured and returning a channel to an already running mapdl mock_instance = pypim.Instance( definition_name="definitions/fake-mapdl", diff --git a/tests/test_licensing.py b/tests/test_licensing.py index 71eecb78ed..b730ec6b2f 100644 --- a/tests/test_licensing.py +++ b/tests/test_licensing.py @@ -182,7 +182,7 @@ def test_license_checker(tmpdir, license_checker): @requires("local") @skip_no_lic_bin -def test_check_license_file(mapdl, tmpdir): +def test_check_license_file(mapdl, cleared, tmpdir): timeout = 15 checker = licensing.LicenseChecker(timeout=timeout) # start the license check in the background diff --git a/tests/test_logging.py b/tests/test_logging.py index ac4a96ac1e..3c416706be 100644 --- a/tests/test_logging.py +++ b/tests/test_logging.py @@ -218,7 +218,7 @@ def test_global_logger_format(): @requires("grpc") -def test_instance_logger_format(mapdl): +def test_instance_logger_format(mapdl, cleared, tmpdir): # Since we cannot read the format of our logger, because pytest just dont show the console output or # if it does, it formats the logger with its own formatter, we are going to check the logger handlers # and output by faking a record. @@ -226,15 +226,22 @@ def test_instance_logger_format(mapdl): # There are things such as filename or class that we cannot evaluate without going # into the code. + msg = "This is a message" + logfile = os.path.join(tmpdir, "mylogfile.log") + + # Adding a log handler + mapdl.logger.log_to_file(logfile, logging.DEBUG) + + # Faking a record log = fake_record( mapdl._log.logger, - msg="This is a message", - level=deflogging.DEBUG, + msg=msg, + level=logging.DEBUG, extra={"instance_name": "172.1.1.1"}, ) assert re.findall("(?:[0-9]{1,3}\.){3}[0-9]{1,3}", log) assert "DEBUG" in log - assert "This is a message" in log + assert msg in log def test_global_methods(caplog): @@ -307,12 +314,12 @@ def test_log_to_file(tmpdir): assert file_msg_debug in text -def test_log_instance_name(mapdl): +def test_log_instance_name(mapdl, cleared): # verify we can access via an instance name LOG[mapdl.name] == mapdl._log -def test_instance_log_to_file(mapdl, tmpdir): +def test_instance_log_to_file(mapdl, cleared, tmpdir): """Testing writing to log file. Since the default loglevel of LOG is error, debug are not normally recorded to it. @@ -321,12 +328,16 @@ def test_instance_log_to_file(mapdl, tmpdir): file_msg_error = "This is a error message" file_msg_debug = "This is a debug message" - if not mapdl._log.file_handler: - mapdl._log.log_to_file(file_path) + mapdl._log.log_to_file(file_path) + mapdl._log.logger.setLevel("ERROR") + for each_handler in mapdl._log.logger.handlers: + each_handler.setLevel("ERROR") mapdl._log.error(file_msg_error) mapdl._log.debug(file_msg_debug) + assert os.path.exists(file_path) + with open(file_path, "r") as fid: text = "".join(fid.readlines()) diff --git a/tests/test_mapdl.py b/tests/test_mapdl.py index 8749850056..d1e5a8fe9c 100644 --- a/tests/test_mapdl.py +++ b/tests/test_mapdl.py @@ -35,7 +35,7 @@ import psutil import pytest -from conftest import PATCH_MAPDL_START, VALID_PORTS, has_dependency +from conftest import PATCH_MAPDL_START, VALID_PORTS, Running_test, has_dependency if has_dependency("pyvista"): from pyvista import MultiBlock @@ -203,11 +203,17 @@ def clearing_cdread_cdwrite_tests(mapdl): - mapdl.finish(mute=True) + mapdl.mute = True + mapdl.finish() # *MUST* be NOSTART. With START fails after 20 calls... # this has been fixed in later pymapdl and MAPDL releases - mapdl.clear("NOSTART", mute=True) - mapdl.prep7(mute=True) + mapdl.clear("NOSTART") + mapdl.header("DEFA") + mapdl.format("DEFA") + mapdl.page("DEFA") + + mapdl.prep7() + mapdl.mute = False def asserting_cdread_cdwrite_tests(mapdl): @@ -251,14 +257,14 @@ def warns_in_cdread_error_log(mapdl, tmpdir): @pytest.mark.parametrize("command", DEPRECATED_COMMANDS) -def test_deprecated_commands(mapdl, command): +def test_deprecated_commands(mapdl, cleared, command): with pytest.raises(CommandDeprecated): method = getattr(mapdl, command) method() @requires("grpc") -def test_internal_name_grpc(mapdl): +def test_internal_name_grpc(mapdl, cleared): assert str(mapdl._ip) in mapdl.name assert str(mapdl._port) in mapdl.name assert "GRPC" in mapdl.name @@ -283,7 +289,7 @@ def test_jobname(mapdl, cleared): @requires("grpc") -def test_server_version(mapdl): +def test_server_version(mapdl, cleared): if mapdl.version == 20.2: assert mapdl._server_version == (0, 0, 0) elif mapdl.version == 21.1: @@ -298,7 +304,7 @@ def test_server_version(mapdl): @requires("grpc") -def test_global_mute(mapdl): +def test_global_mute(mapdl, cleared): mapdl.mute = True assert mapdl.mute is True assert mapdl.prep7() is None @@ -360,12 +366,12 @@ def test_no_results(mapdl, cleared, tmpdir): mapdl.download_result(pth) -def test_empty(mapdl): +def test_empty(mapdl, cleared): with pytest.raises(ValueError): mapdl.run("") -def test_multiline_fail(mapdl): +def test_multiline_fail(mapdl, cleared): with pytest.raises(ValueError, match="Use ``input_strings``"): mapdl.run(CMD_BLOCK) @@ -390,14 +396,14 @@ def test_input_strings(mapdl, cleared): assert isinstance(mapdl.input_strings(CMD_BLOCK.splitlines()), str) -def test_str(mapdl): +def test_str(mapdl, cleared): mapdl_str = str(mapdl) assert "Product:" in mapdl_str assert "MAPDL Version" in mapdl_str assert str(mapdl.version) in mapdl_str -def test_version(mapdl): +def test_version(mapdl, cleared): assert isinstance(mapdl.version, float) # Checking MAPDL version expected_version = float( datetime.now().year - 2000 + 1 + 1 @@ -424,15 +430,15 @@ def test_comment(cleared, mapdl): def test_basic_command(cleared, mapdl): - resp = mapdl.prep7() resp = mapdl.finish() assert "ROUTINE COMPLETED" in resp -def test_allow_ignore(mapdl): - mapdl.clear() +def test_allow_ignore(mapdl, cleared): mapdl.allow_ignore = False assert mapdl.allow_ignore is False + mapdl.finish() + with pytest.raises(pymapdl.errors.MapdlInvalidRoutineError): mapdl.k() @@ -454,7 +460,6 @@ def test_chaining(mapdl, cleared): with mapdl.chain_commands: mapdl.prep7() else: - mapdl.prep7() n_kp = 1000 with mapdl.chain_commands: for i in range(1, 1 + n_kp): @@ -463,20 +468,18 @@ def test_chaining(mapdl, cleared): assert mapdl.geometry.n_keypoint == 1000 -def test_error(mapdl): +def test_error(mapdl, cleared): with pytest.raises(MapdlRuntimeError): - mapdl.prep7() mapdl.a(0, 0, 0, 0) -def test_ignore_errors(mapdl): +def test_ignore_errors(mapdl, cleared): mapdl.ignore_errors = False assert not mapdl.ignore_errors mapdl.ignore_errors = True assert mapdl.ignore_errors is True # verify that an error is not raised - mapdl.prep7(mute=True) out = mapdl._run("A, 0, 0, 0") assert "*** ERROR ***" in out @@ -485,7 +488,7 @@ def test_ignore_errors(mapdl): @requires("grpc") -def test_list(mapdl, tmpdir): +def test_list(mapdl, cleared, tmpdir): """Added for backwards compatibility""" fname = "tmp.txt" filename = str(tmpdir.mkdir("tmpdir").join(fname)) @@ -499,7 +502,7 @@ def test_list(mapdl, tmpdir): @requires("grpc") -def test_invalid_input(mapdl): +def test_invalid_input(mapdl, cleared): with pytest.raises(FileNotFoundError): mapdl.input("thisisnotafile") @@ -523,7 +526,7 @@ def test_keypoints(cleared, mapdl): @requires("pyvista") -def test_lines(cleared, mapdl): +def test_lines(mapdl, cleared): assert mapdl.geometry.n_line == 0 k0 = mapdl.k("", 0, 0, 0) @@ -544,7 +547,7 @@ def test_lines(cleared, mapdl): @requires("local") -def test_apdl_logging_start(tmpdir, mapdl): +def test_apdl_logging_start(tmpdir, mapdl, cleared): filename = str(tmpdir.mkdir("tmpdir").join("tmp.inp")) launch_options = launch_mapdl( @@ -556,6 +559,10 @@ def test_apdl_logging_start(tmpdir, mapdl): ) assert filename in launch_options["log_apdl"] + + # remove logger first + mapdl._apdl_log = None + # activating logger mapdl.open_apdl_log(filename, mode="w") @@ -579,7 +586,7 @@ def test_apdl_logging_start(tmpdir, mapdl): mapdl._close_apdl_log() -def test_apdl_logging(mapdl, tmpdir): +def test_apdl_logging(mapdl, cleared, tmpdir): tmp_dir = tmpdir.mkdir("tmpdir") file_name = "tmp_logger.log" file_path = str(tmp_dir.join(file_name)) @@ -741,7 +748,7 @@ def test_elements(cleared, mapdl): np.random.random((10, 3, 3)), ), ) -def test_set_get_parameters(mapdl, parm): +def test_set_get_parameters(mapdl, cleared, parm): parm_name = pymapdl.misc.random_string(20) mapdl.parameters[parm_name] = parm @@ -762,12 +769,12 @@ def test_set_parameters_arr_to_scalar(mapdl, cleared): mapdl.parameters["PARM"] = 2 -def test_set_parameters_string_spaces(mapdl): +def test_set_parameters_string_spaces(mapdl, cleared): with pytest.raises(ValueError): mapdl.parameters["PARM"] = "string with spaces" -def test_set_parameters_too_long(mapdl): +def test_set_parameters_too_long(mapdl, cleared): with pytest.raises( ValueError, match="Length of ``name`` must be 32 characters or less" ): @@ -780,7 +787,6 @@ def test_set_parameters_too_long(mapdl): def test_builtin_parameters(mapdl, cleared): - mapdl.prep7() assert mapdl.parameters.routine == "PREP7" mapdl.units("SI") @@ -825,7 +831,6 @@ def test_partial_mesh_nnum2(mapdl, make_block): def test_cyclic_solve(mapdl, cleared): # build the cyclic model - mapdl.prep7() mapdl.shpp("off") mapdl.cdread("db", os.path.join(test_files, "sector.cdb")) mapdl.prep7() @@ -858,7 +863,7 @@ def test_cyclic_solve(mapdl, cleared): ) ), ) -def test_load_table(mapdl, dim_rows, dim_cols): +def test_load_table(mapdl, cleared, dim_rows, dim_cols): my_conv = np.random.rand(dim_rows, dim_cols) my_conv[:, 0] = np.arange(dim_rows) # "time" values @@ -866,7 +871,7 @@ def test_load_table(mapdl, dim_rows, dim_cols): assert np.allclose(mapdl.parameters["my_conv"], my_conv[:, 1:], 1e-7) -def test_load_table_error_ascending_row(mapdl): +def test_load_table_error_ascending_row(mapdl, cleared): my_conv = np.ones((3, 3)) my_conv[1, 0] = 4 with pytest.raises(ValueError, match="requires that the first column is in"): @@ -875,7 +880,7 @@ def test_load_table_error_ascending_row(mapdl): @pytest.mark.parametrize("dimx", [1, 3, 10]) @pytest.mark.parametrize("dimy", [1, 3, 10]) -def test_load_array(mapdl, dimx, dimy): +def test_load_array(mapdl, cleared, dimx, dimy): my_conv = np.random.rand(dimx, dimy) mapdl.load_array("my_conv", my_conv) @@ -893,13 +898,13 @@ def test_load_array(mapdl, dimx, dimy): np.zeros((3, 3)), ], ) -def test_load_array_types(mapdl, array): +def test_load_array_types(mapdl, cleared, array): mapdl.load_array("myarr", array) assert np.allclose(mapdl.parameters["myarr"], array, rtol=1e-7) @pytest.mark.parametrize("array", [[1, 3, 10], np.random.randint(1, 20, size=(5,))]) -def test_load_array_failure_types(mapdl, array): +def test_load_array_failure_types(mapdl, cleared, array): array[0] = array[0] + 1 # This is to avoid having all elements equal #1061 mapdl.load_array("myarr", array) array = np.array(array) @@ -915,7 +920,6 @@ def test_lssolve(mapdl, cleared): mapdl.mute = True mapdl.run("/units,user,0.001,0.001,1,1,0,1,1,1") - mapdl.prep7() mapdl.et(1, 182) mapdl.mp("ex", 1, 210e3) mapdl.mp("nuxy", 1, 0.33) @@ -1153,7 +1157,7 @@ def test_inval_commands_silent(mapdl, tmpdir, cleared): @requires("local") -def test_path_without_spaces(mapdl, path_tests): +def test_path_without_spaces(mapdl, cleared, path_tests): old_path = mapdl.directory try: resp = mapdl.cwd(path_tests.path_without_spaces) @@ -1163,7 +1167,7 @@ def test_path_without_spaces(mapdl, path_tests): @requires("local") -def test_path_with_spaces(mapdl, path_tests): +def test_path_with_spaces(mapdl, cleared, path_tests): old_path = mapdl.directory try: resp = mapdl.cwd(path_tests.path_with_spaces) @@ -1173,12 +1177,12 @@ def test_path_with_spaces(mapdl, path_tests): @requires("local") -def test_path_with_single_quote(mapdl, path_tests): +def test_path_with_single_quote(mapdl, cleared, path_tests): with pytest.raises(MapdlRuntimeError): mapdl.cwd(path_tests.path_with_single_quote) -def test_cwd(mapdl, tmpdir): +def test_cwd(mapdl, cleared, tmpdir): old_path = mapdl.directory if mapdl.is_local: tempdir_ = tmpdir @@ -1204,7 +1208,7 @@ def test_cwd(mapdl, tmpdir): @requires("nocicd") @requires("local") -def test_inquire(mapdl): +def test_inquire(mapdl, cleared): # Testing basic functions (First block: Functions) assert "apdl" in mapdl.inquire("", "apdl").lower() @@ -1233,14 +1237,13 @@ def test_inquire(mapdl): def test_ksel(mapdl, cleared): mapdl.k(1, 0, 0, 0) - mapdl.prep7() assert "SELECTED" in mapdl.ksel("S", "KP", vmin=1, return_mapdl_output=True) assert "SELECTED" in mapdl.ksel("S", "KP", "", 1, return_mapdl_output=True) assert 1 in mapdl.ksel("S", "KP", vmin=1) -def test_get_file_path(mapdl, tmpdir): +def test_get_file_path(mapdl, cleared, tmpdir): fname = "dummy.txt" fobject = tmpdir.join(fname) fobject.write("Dummy file for testing") @@ -1302,20 +1305,20 @@ def test_tbft(mapdl, cleared, tmpdir, option2, option3, option4): # mapdl.tbft("FADD", mat_id, "HYPER", "MOONEY", "3") -def test_tbft_not_found(mapdl): +def test_tbft_not_found(mapdl, cleared): with pytest.raises(FileNotFoundError): - mapdl.prep7(mute=True) mat_id = mapdl.get_value("MAT", 0, "NUM", "MAX") + 1 mapdl.tbft("FADD", mat_id, "HYPER", "MOONEY", "3", mute=True) mapdl.tbft("EADD", mat_id, "UNIA", "non_existing.file", "", "", mute=True) -def test_rescontrol(mapdl): +def test_rescontrol(mapdl, cleared): # Making sure we have the maximum number of arguments. + mapdl.solution() mapdl.rescontrol("DEFINE", "", "", "", "", "XNNN") # This is default -def test_get_with_gopr(mapdl): +def test_get_with_gopr(mapdl, cleared): """Get should work independently of the /gopr state.""" mapdl._run("/gopr") @@ -1336,7 +1339,7 @@ def test_get_with_gopr(mapdl): assert mapdl.wrinqr(1) == 1 -def test_print_com(mapdl, capfd): +def test_print_com(mapdl, cleared, capfd): mapdl.print_com = True string_ = "Testing print" mapdl.com(string_) @@ -1387,7 +1390,7 @@ def test_extra_argument_in_get(mapdl, make_block): @pytest.mark.parametrize("value", [1e-6, 1e-5, 1e-3, None]) -def test_seltol(mapdl, value): +def test_seltol(mapdl, cleared, value): if value: assert "SELECT TOLERANCE=" in mapdl.seltol(value) else: @@ -1395,12 +1398,12 @@ def test_seltol(mapdl, value): def test_mpfunctions(mapdl, cube_solve, capsys): - mapdl.prep7() - # check writing to file fname = "test" ext = "mp1" + mapdl.prep7() + assert f"WRITE OUT MATERIAL PROPERTY LIBRARY TO FILE=" in mapdl.mpwrite(fname, ext) assert f"{fname}.{ext}" in mapdl.list_files() @@ -1479,14 +1482,14 @@ def test_mpfunctions(mapdl, cube_solve, capsys): mapdl.mpwrite("/test_dir/test", "mp") -def test_mapdl_str(mapdl): +def test_mapdl_str(mapdl, cleared): out = str(mapdl) assert "ansys" in out.lower() assert "Product" in out assert "MAPDL Version" in out -def test_equal_in_comments_and_title(mapdl): +def test_equal_in_comments_and_title(mapdl, cleared): mapdl.com("=====") mapdl.title("This is = ") mapdl.title("This is '=' ") @@ -1561,7 +1564,7 @@ def test_file_command_remote(mapdl, cube_solve, tmpdir): @pytest.mark.parametrize("value", [2, np.array([1, 2, 3]), "asdf"]) -def test_parameter_deletion(mapdl, value): +def test_parameter_deletion(mapdl, cleared, value): mapdl.parameters["mypar"] = value assert "mypar".upper() in mapdl.starstatus() del mapdl.parameters["mypar"] @@ -1592,8 +1595,7 @@ def test_get_variable_nsol_esol_wrappers(mapdl, coupled_example): assert np.allclose(variable, esol_1) -def test_retain_routine(mapdl): - mapdl.prep7() +def test_retain_routine(mapdl, cleared): routine = "POST26" with mapdl.run_as_routine(routine): assert mapdl.parameters.routine == routine @@ -1602,7 +1604,6 @@ def test_retain_routine(mapdl): def test_non_interactive(mapdl, cleared): with mapdl.non_interactive: - mapdl.prep7() mapdl.k(1, 1, 1, 1) mapdl.k(2, 2, 2, 2) @@ -1611,7 +1612,6 @@ def test_non_interactive(mapdl, cleared): def test_ignored_command(mapdl, cleared): mapdl.ignore_errors = False - mapdl.prep7(mute=True) mapdl.n(mute=True) with pytest.raises(MapdlCommandIgnoredError, match="command is ignored"): mapdl.f(1, 1, 1, 1) @@ -1688,7 +1688,7 @@ def test_set_list(mapdl, cube_solve): assert not isinstance(obj, CommandListingOutput) -def test_mode(mapdl): +def test_mode(mapdl, cleared): assert mapdl.connection == "grpc" assert mapdl.is_grpc assert not mapdl.is_corba @@ -1707,7 +1707,7 @@ def test_mode(mapdl): mapdl._mode = "grpc" # Going back to default -def test_remove_lock_file(mapdl, tmpdir): +def test_remove_lock_file(mapdl, cleared, tmpdir): tmpdir_ = tmpdir.mkdir("ansys") lock_file = tmpdir_.join("file.lock") with open(lock_file, "w") as fid: @@ -1717,21 +1717,21 @@ def test_remove_lock_file(mapdl, tmpdir): assert not os.path.exists(lock_file) -def test_is_local(mapdl): +def test_is_local(mapdl, cleared): assert mapdl.is_local == mapdl._local -def test_on_docker(mapdl): +def test_on_docker(mapdl, cleared): assert mapdl.on_docker == mapdl._on_docker -def test_deprecation_allow_ignore_warning(mapdl): +def test_deprecation_allow_ignore_warning(mapdl, cleared): with pytest.warns(DeprecationWarning, match="'allow_ignore' is being deprecated"): mapdl.allow_ignore = True mapdl.ignore_errors = False -def test_deprecation_allow_ignore_errors_mapping(mapdl): +def test_deprecation_allow_ignore_errors_mapping(mapdl, cleared): mapdl.allow_ignore = True assert mapdl.allow_ignore == mapdl.ignore_errors @@ -1745,7 +1745,7 @@ def test_deprecation_allow_ignore_errors_mapping(mapdl): assert mapdl.allow_ignore == mapdl.ignore_errors -def test_check_stds(mapdl): +def test_check_stds(mapdl, cleared): mapdl._stdout = "everything is going ok" mapdl._stderr = "" @@ -1788,7 +1788,7 @@ def intercept_unary_unary(continuation, client_call_details, request): pymapdl.Mapdl(channel=bad_channel_with_interceptor, timeout=1) -def test_post_mortem_checks_no_process(mapdl): +def test_post_mortem_checks_no_process(mapdl, cleared): # Early exit old_process = mapdl._mapdl_process old_mode = mapdl._mode @@ -1810,7 +1810,7 @@ def test_post_mortem_checks_no_process(mapdl): mapdl._mode = old_mode -def test_avoid_non_interactive(mapdl): +def test_avoid_non_interactive(mapdl, cleared): with mapdl.non_interactive: mapdl.com("comment A") mapdl.com("comment B", avoid_non_interactive=True) @@ -1822,7 +1822,7 @@ def test_avoid_non_interactive(mapdl): assert any(["comment C" in cmd for cmd in stored_commands]) -def test_get_file_name(mapdl): +def test_get_file_name(mapdl, cleared): file_ = "asdf/qwert/zxcv.asd" assert mapdl._get_file_name(file_) == file_ assert mapdl._get_file_name(file_, "asdf") == file_ + ".asdf" @@ -1834,7 +1834,7 @@ def test_get_file_name(mapdl): @requires("local") -def test_cache_pids(mapdl): +def test_cache_pids(mapdl, cleared): if mapdl.version == 23.2: pytest.skip(f"Flaky test in MAPDL 23.2") # I'm not sure why. @@ -1849,11 +1849,11 @@ def test_cache_pids(mapdl): @requires("local") -def test_process_is_alive(mapdl): +def test_process_is_alive(mapdl, cleared): assert mapdl.process_is_alive -def test_force_output(mapdl): +def test_force_output(mapdl, cleared): mapdl.mute = True with mapdl.force_output: assert mapdl.prep7() @@ -1875,7 +1875,7 @@ def test_force_output(mapdl): assert mapdl.prep7() -def test_session_id(mapdl, running_test): +def test_session_id(mapdl, cleared, running_test): mapdl._strict_session_id_check = True assert mapdl._session_id is not None @@ -1906,7 +1906,7 @@ def test_session_id(mapdl, running_test): mapdl._strict_session_id_check = False -def test_check_empty_session_id(mapdl): +def test_check_empty_session_id(mapdl, cleared): # it should run normal mapdl._session_id_ = None assert mapdl._check_session_id() is None @@ -1916,7 +1916,10 @@ def test_check_empty_session_id(mapdl): @requires("requests") # Requires 'requests' package def test_igesin_whitespace(mapdl, cleared, tmpdir): - bracket_file = pymapdl.examples.download_bracket() + # make sure we download the IGES file + with Running_test(False): # allow access to internet + bracket_file = pymapdl.examples.download_bracket() + assert os.path.isfile(bracket_file) # moving to another location @@ -1981,7 +1984,7 @@ def test_input_inside_non_interactive(mapdl, cleared): os.remove("myinput.inp") -def test_rlblock_rlblock_num(mapdl): +def test_rlblock_rlblock_num(mapdl, cleared): def num_(): return np.round(np.random.random(), 4) @@ -2012,7 +2015,7 @@ def test_download_results_non_local(mapdl, cube_solve): assert isinstance(mapdl.result, Result) -def test__flush_stored(mapdl): +def test__flush_stored(mapdl, cleared): with mapdl.non_interactive: mapdl.com("mycomment") mapdl.com("another comment") @@ -2023,17 +2026,17 @@ def test__flush_stored(mapdl): assert not mapdl._stored_commands -def test_exited(mapdl): +def test_exited(mapdl, cleared): assert mapdl.exited == mapdl._exited assert isinstance(mapdl.exited, bool) -def test_exiting(mapdl): +def test_exiting(mapdl, cleared): assert mapdl.exiting == mapdl._exiting assert isinstance(mapdl.exiting, bool) -def test_check_status(mapdl): +def test_check_status(mapdl, cleared): assert mapdl.check_status == "OK" mapdl._exited = True @@ -2047,24 +2050,24 @@ def test_check_status(mapdl): mapdl._exiting = False -def test_ip(mapdl): +def test_ip(mapdl, cleared): assert mapdl._ip == mapdl.ip assert isinstance(mapdl.ip, str) -def test_port(mapdl): +def test_port(mapdl, cleared): assert mapdl.port == mapdl._port assert isinstance(mapdl.port, int) -def test_distributed(mapdl): +def test_distributed(mapdl, cleared): if ON_CI and IS_SMP and not ON_LOCAL: assert not mapdl._distributed else: assert mapdl._distributed -def test_non_used_kwargs(mapdl): +def test_non_used_kwargs(mapdl, cleared): with pytest.warns(UserWarning): mapdl.prep7(non_valid_argument=2) @@ -2076,15 +2079,14 @@ def test_non_used_kwargs(mapdl): mapdl.run("/prep7", True, None, **kwarg) -def test_non_valid_kwarg(mapdl): - mapdl.prep7() +def test_non_valid_kwarg(mapdl, cleared): mapdl.blc4(0, 0, 1, 1, 1) with pytest.warns(UserWarning): mapdl.cdwrite(options="DB", fname="test1", ext="cdb") -def test_check_parameter_names(mapdl): +def test_check_parameter_names(mapdl, cleared): with pytest.raises(ValueError): mapdl.parameters["_dummy"] = 1 @@ -2203,7 +2205,7 @@ def test_saving_selection_context(mapdl, cube_solve): assert "nod_selection_4" not in mapdl.components -def test_inquire_invalid(mapdl): +def test_inquire_invalid(mapdl, cleared): with pytest.raises(ValueError, match="Arguments of this method have changed"): mapdl.inquire("directory") @@ -2211,22 +2213,22 @@ def test_inquire_invalid(mapdl): mapdl.inquire("dummy", "hi") -def test_inquire_default(mapdl): - mapdl.title = "heeeelloo" +def test_inquire_default(mapdl, cleared): + mapdl.title("heeeelloo") assert Path(mapdl.directory) == Path(mapdl.inquire()) -def test_vwrite_error(mapdl): +def test_vwrite_error(mapdl, cleared): with pytest.raises(MapdlRuntimeError): mapdl.vwrite("adf") -def test_mwrite_error(mapdl): +def test_mwrite_error(mapdl, cleared): with pytest.raises(MapdlRuntimeError): mapdl.mwrite("adf") -def test_vwrite(mapdl): +def test_vwrite(mapdl, cleared): with mapdl.non_interactive: mapdl.run("/out,test_vwrite.txt") mapdl.vwrite("'hello'") @@ -2249,7 +2251,7 @@ def test_get_array_non_interactive(mapdl, solved_box): mapdl.get_array("asdf", "2") -def test_default_file_type_for_plots(mapdl): +def test_default_file_type_for_plots(mapdl, cleared): assert mapdl.default_file_type_for_plots with pytest.raises(ValueError): @@ -2259,7 +2261,7 @@ def test_default_file_type_for_plots(mapdl): @requires("matplotlib") -def test_use_vtk(mapdl): +def test_use_vtk(mapdl, cleared): assert isinstance(mapdl.use_vtk, bool) prev = mapdl.use_vtk @@ -2271,7 +2273,7 @@ def test_use_vtk(mapdl): @requires("local") @pytest.mark.xfail(reason="Flaky test. See #2435") -def test_remove_temp_dir_on_exit(mapdl, tmpdir): +def test_remove_temp_dir_on_exit(mapdl, cleared, tmpdir): path = os.path.join(tempfile.gettempdir(), "ansys_" + random_string()) os.makedirs(path) filename = os.path.join(path, "file.txt") @@ -2292,7 +2294,7 @@ def test_remove_temp_dir_on_exit(mapdl, tmpdir): @requires("local") @requires("nostudent") @pytest.mark.xfail(reason="Flaky test. See #2435") -def test_remove_temp_dir_on_exit(mapdl): +def test_remove_temp_dir_on_exit_with_launch_mapdl(mapdl, cleared): mapdl_2 = launch_mapdl(remove_temp_dir_on_exit=True, port=PORT1) path_ = mapdl_2.directory @@ -2306,7 +2308,7 @@ def test_remove_temp_dir_on_exit(mapdl): assert not all([psutil.pid_exists(pid) for pid in pids]) -def test_sys(mapdl): +def test_sys(mapdl, cleared): assert "hi" in mapdl.sys("echo 'hi'") @@ -2320,7 +2322,6 @@ def test_sys(mapdl): ), ) def test_lgwrite(mapdl, cleared, filename, ext, remove_grpc_extra, kedit): - mapdl.prep7() mapdl.k(1, 0, 0, 0, mute=True) mapdl.k(2, 2, 0, 0) @@ -2403,7 +2404,6 @@ def test_screenshot(mapdl, make_block, tmpdir): def test_force_command_ignored_not_active_set(mapdl, cleared): - mapdl.prep7() mapdl.et("", 227) mapdl.keyopt(1, 1) # Thermal-Piezoelectric mapdl.n(1, 0, 0, 0) @@ -2413,26 +2413,23 @@ def test_force_command_ignored_not_active_set(mapdl, cleared): def test_force_command_when_no_nodes(mapdl, cleared): - mapdl.prep7() mapdl.et(1, 189) with pytest.raises(MapdlCommandIgnoredError, match="No nodes defined"): mapdl.f(1, "CHRG", 0) -def test_not_correct_et_element(mapdl): - mapdl.clear() - mapdl.prep7() +def test_not_correct_et_element(mapdl, cleared): mapdl.et(1, 227) with pytest.warns(UserWarning, match="is normal behavior when a CDB file is used"): mapdl.keyopt(1, 222) -def test_ctrl(mapdl): +def test_ctrl(mapdl, cleared): mapdl._ctrl("set_verb", 5) # Setting verbosity on the server mapdl._ctrl("set_verb", 0) # Returning to non-verbose -def test_cleanup_loggers(mapdl): +def test_cleanup_loggers(mapdl, cleared): assert mapdl.logger is not None assert mapdl.logger.hasHandlers() assert mapdl.logger.logger.handlers @@ -2444,7 +2441,7 @@ def test_cleanup_loggers(mapdl): assert mapdl.logger.file_handler is None -def test_no_flush_stored(mapdl): +def test_no_flush_stored(mapdl, cleared): assert not mapdl._store_commands mapdl._store_commands = True mapdl._stored_commands = [] @@ -2478,7 +2475,7 @@ def test_ip_hostname_in_start_parm(ip): del mapdl -def test_directory_setter(mapdl): +def test_directory_setter(mapdl, cleared): # Testing edge cases prev_path = mapdl._path @@ -2500,7 +2497,7 @@ def test_directory_setter(mapdl): mapdl._path = prev_path -def test_cwd_changing_directory(mapdl): +def test_cwd_changing_directory(mapdl, cleared): prev_path = mapdl._path mapdl._path = None diff --git a/tests/test_mesh_grpc.py b/tests/test_mesh_grpc.py index ae4eb13a0b..afbf339b4a 100644 --- a/tests/test_mesh_grpc.py +++ b/tests/test_mesh_grpc.py @@ -34,9 +34,7 @@ from ansys.mapdl.core import examples -def test_empty_model(mapdl): - mapdl.clear() - +def test_empty_model(mapdl, cleared): assert mapdl.mesh.nnum.size == 0 assert mapdl.mesh.enum.size == 0 @@ -73,13 +71,13 @@ def test_repr(mapdl, cube_geom_and_mesh): assert "Number of Element Types" in out -def test_mapdl(mapdl): +def test_mapdl(mapdl, cleared): from ansys.mapdl.core.mapdl import MapdlBase assert isinstance(mapdl.mesh._mapdl, MapdlBase) -def test_local(mapdl): +def test_local(mapdl, cleared): assert isinstance(mapdl.mesh.local, bool) assert mapdl._local == mapdl.mesh.local diff --git a/tests/test_misc.py b/tests/test_misc.py index 1219da9675..ed2be5c6bb 100644 --- a/tests/test_misc.py +++ b/tests/test_misc.py @@ -116,7 +116,6 @@ def fun( def test_no_return(mapdl, cleared): - mapdl.prep7() @no_return def fun( @@ -130,7 +129,7 @@ def fun( @pytest.mark.parametrize("file_", ["dummy.dumdum", "dumdum.dummy"]) -def test_load_file_local(mapdl, tmpdir, file_): +def test_load_file_local(mapdl, cleared, tmpdir, file_): """Checking 'load_file' function. In CICD it seems we cannot write to the root folder '/'. diff --git a/tests/test_parameters.py b/tests/test_parameters.py index 3d9ef44c01..fa6cda4de6 100644 --- a/tests/test_parameters.py +++ b/tests/test_parameters.py @@ -118,7 +118,7 @@ 1e61, ], ) -def test__get_parameter_array(mapdl, number): +def test__get_parameter_array(mapdl, cleared, number): name = "param_array" # Testing 1D arrays @@ -182,7 +182,7 @@ def parameters_name(mapdl, func, par_name): "array3d_(1,1,1)", ], ) -def test_parameters_name(mapdl, func, par_name): +def test_parameters_name(mapdl, cleared, func, par_name): parameters_name(mapdl, func, par_name) @@ -281,13 +281,13 @@ def test_parameters_name(mapdl, func, par_name): ), ], ) -def test_parameters_name_error(mapdl, func, par_name): +def test_parameters_name_error(mapdl, cleared, func, par_name): with pytest.raises(ValueError): parameters_name(mapdl, func, par_name) def test_contain_iter(mapdl, cleared): - mapdl.clear() # to check that #1107 is solved + mapdl.finish() # to check that #1107 is solved mapdl.parameters["TWO"] = 2.0 assert 2.0 == mapdl.parameters["TWO"] assert "TWO" in mapdl.parameters @@ -299,7 +299,7 @@ def test_contain_iter(mapdl, cleared): @pytest.mark.parametrize("number", [1 / 3, 1 / 7, 0.0181681816816816168168168]) -def test_double_parameter_get(mapdl, number): +def test_double_parameter_get(mapdl, number, cleared): # Running grpc method mapdl.parameters["value"] = number @@ -324,7 +324,7 @@ def test_double_parameter_get(mapdl, number): mapdl._name = mapdl_name -def test_parameter_delete_raise(mapdl): +def test_parameter_delete_raise(mapdl, cleared): with pytest.raises(KeyError, match="does not exist"): del mapdl.parameters["not-a-parm"] @@ -368,7 +368,7 @@ def test_interp_star_status(status, check): assert output["PORT"]["value"] == 50054.0 -def test_str_arrays(mapdl): +def test_str_arrays(mapdl, cleared): mapdl.run("*dim, mystrarr, string, 80") mapdl.run("mystrarr(1) = 'hello there!'") @@ -384,7 +384,7 @@ def test_str_arrays(mapdl): ] -def test_3d_array(mapdl): +def test_3d_array(mapdl, cleared): mapdl.dim("myarr", "array", 2, 2, 2) mapdl.run("myarr(1,1,1)= 100") mapdl.run("myarr(1,1,2)= 200") @@ -397,7 +397,7 @@ def test_3d_array(mapdl): ) -def test_parameter_with_spaces(mapdl): +def test_parameter_with_spaces(mapdl, cleared): string_ = "DEV:F10X, front weights " mapdl.run(f"*SET,SIMULATION,'{string_}'") mapdl.parsav() @@ -409,7 +409,7 @@ def test_parameter_with_spaces(mapdl): assert string_.strip() == mapdl.parameters["SIMULATION"] -def test_parameters_keys(mapdl): +def test_parameters_keys(mapdl, cleared): mapdl.parameters["MYPAR"] = 1234 assert "MYPAR" in list(mapdl.parameters.keys()) @@ -451,7 +451,7 @@ def test_non_existing_parameter(mapdl, cleared): mapdl.parameters["A"] -def test_non_interactive(mapdl): +def test_non_interactive(mapdl, cleared): mapdl.parameters["asdf"] = 2 with pytest.raises(MapdlRuntimeError): with mapdl.non_interactive: diff --git a/tests/test_plotting.py b/tests/test_plotting.py index 4c9ab3f71e..742f819a8d 100644 --- a/tests/test_plotting.py +++ b/tests/test_plotting.py @@ -42,9 +42,7 @@ @pytest.fixture -def boundary_conditions_example(mapdl): - mapdl.clear() - mapdl.prep7() +def boundary_conditions_example(mapdl, cleared): mapdl.et("", 189) mapdl.n(1, 0, 0, 0) @@ -93,10 +91,7 @@ def boundary_conditions_example(mapdl): @pytest.fixture -def block_example_coupled(mapdl): - mapdl.clear() - mapdl.prep7() - +def block_example_coupled(mapdl, cleared): mapdl.et(1, 226) mapdl.keyopt(1, 1, 1011) # Thermal-Piezoelectric @@ -206,7 +201,7 @@ def test_download_file_with_vkt_false(mapdl, cube_solve, tmpdir): "eplot", ], ) -def test_plots_no_vtk(mapdl, method): +def test_plots_no_vtk(mapdl, cube_solve, method): _ = getattr(mapdl, method)(vtk=False) @@ -301,9 +296,7 @@ def test_eplot_savefig(mapdl, make_block, tmpdir): "field", ["UX", "UY", "UZ", "FX", "FY", "FZ", "TEMP", "HEAT", "VOLT", "CHRG"] ) @pytest.mark.parametrize("magnitude", [0, 50, 500]) -def test_single_glyph(mapdl, field, magnitude, verify_image_cache): - mapdl.clear() - mapdl.prep7() +def test_single_glyph(mapdl, cleared, field, magnitude, verify_image_cache): mapdl.et(1, 226) mapdl.keyopt(1, 1, 1011) # Thermal-Piezoelectric mapdl.n(1, 0, 0, 0) @@ -476,7 +469,7 @@ def test_bc_plot_bc_target_error(mapdl, boundary_conditions_example, bc_target): ) -def test_bc_no_mapdl(mapdl): +def test_bc_no_mapdl(mapdl, cleared): with pytest.raises(ValueError): pl = MapdlPlotter() pl.plot([], [], [], plot_bc=True) @@ -1009,7 +1002,7 @@ def filtering(file_name): os.remove(last_png) -def test_file_type_for_plots(mapdl): +def test_file_type_for_plots(mapdl, cleared): assert mapdl.file_type_for_plots in ["PNG", "TIFF", "PNG", "VRML", "TERM", "CLOSE"] mapdl.file_type_for_plots = "TIFF" @@ -1150,8 +1143,6 @@ def test_node_numbering_order(mapdl, cleared): def test_lplot_line(mapdl, cleared): - mapdl.prep7() - # Create keypoints 3 keypoints mapdl.k(1, 0, 0, 0) mapdl.k(2, 1, 0, 0) @@ -1193,7 +1184,6 @@ def test_xplot_not_changing_geo_selection(mapdl, cleared, func, entity, partial) def test_xplot_not_changing_geo_selection2(mapdl, cleared): - mapdl.prep7() mapdl.rectng(0, 1, 0, 1) mapdl.cm("area1", "area") mapdl.cmsel("u", "area1") diff --git a/tests/test_post.py b/tests/test_post.py index fd1b1d45a7..7eca8fcbba 100644 --- a/tests/test_post.py +++ b/tests/test_post.py @@ -27,7 +27,7 @@ import numpy as np import pytest -from conftest import NullContext, has_dependency, requires +from conftest import NullContext, TestClass, has_dependency, requires if has_dependency("ansys-tools-visualization_interface"): from pyvista.plotting.renderer import CameraPosition @@ -60,14 +60,12 @@ def test_repr(mapdl, cleared): assert mapdl.set("LIST") in repr_ -class Test_static_solve: +class Test_static_solve(TestClass): @staticmethod @pytest.fixture(scope="class") def static_solve(mapdl): mapdl.mute = True - mapdl.finish() - mapdl.clear() # cylinder and mesh parameters # torque = 100 @@ -79,7 +77,6 @@ def static_solve(mapdl): force = 100 / radius pressure = force / (h_tip * 2 * np.pi * radius) - mapdl.prep7() mapdl.et(1, 186) mapdl.et(2, 154) mapdl.r(1) @@ -136,17 +133,29 @@ def static_solve(mapdl): # mapdl.eqslv('pcg', 1e-8) mapdl.solve() + mapdl.mute = False + + mapdl.save("static_solve", slab="all") + + @pytest.fixture(scope="function") + def resume(self, mapdl, static_solve): + self.mapdl = mapdl + + mapdl.prep7() + mapdl.resume("static_solve") + # necessary for any prnsol printouts mapdl.header("off", "off", "off", "off", "off", "off") nsigfig = 10 mapdl.format("", "E", nsigfig + 9, nsigfig) - # mapdl.post1(mute=True) - # mapdl.set(1, 1) - mapdl.mute = False + + mapdl.post1() + mapdl.allsel() + mapdl.set("last") @staticmethod @pytest.mark.parametrize("comp", ["X", "Y", "z"]) # lowercase intentional - def test_disp(mapdl, static_solve, comp): + def test_disp(mapdl, resume, comp): disp_from_grpc = mapdl.post_processing.nodal_displacement(comp) mapdl.post1(mute=True) @@ -157,7 +166,7 @@ def test_disp(mapdl, static_solve, comp): assert np.allclose(disp_from_grpc, disp_from_prns) @staticmethod - def test_enum_all(mapdl, static_solve): + def test_enum_all(mapdl, resume): # ensure that element selection status has no effect on the all_enum try: n_elem = mapdl.mesh.n_elem @@ -170,7 +179,7 @@ def test_enum_all(mapdl, static_solve): mapdl.allsel(mute=True) @staticmethod - def test_disp_norm_all(mapdl, static_solve): + def test_disp_norm_all(mapdl, resume): # test norm disp_norm = mapdl.post_processing.nodal_displacement("NORM") @@ -189,7 +198,7 @@ def test_disp_norm_all(mapdl, static_solve): @pytest.mark.parametrize( "comp", ["X", "Y", "z", "norm", "all"] ) # lowercase intentional - def test_disp_plot(mapdl, static_solve, comp): + def test_disp_plot(mapdl, resume, comp): if comp == "all": context = pytest.raises( ValueError, match='"ALL" not allowed in this context' @@ -207,7 +216,7 @@ def test_disp_plot(mapdl, static_solve, comp): @staticmethod @requires("ansys-tools-visualization_interface") - def test_disp_plot_subselection(mapdl, static_solve, verify_image_cache): + def test_disp_plot_subselection(mapdl, resume, verify_image_cache): verify_image_cache.skip = True # skipping image verification mapdl.nsel("S", "NODE", vmin=500, vmax=2000, mute=True) @@ -221,7 +230,7 @@ def test_disp_plot_subselection(mapdl, static_solve, verify_image_cache): mapdl.allsel() @staticmethod - def test_nodal_eqv_stress(mapdl, static_solve): + def test_nodal_eqv_stress(mapdl, resume): mapdl.post1(mute=True) mapdl.set(1, 1, mute=True) @@ -236,13 +245,13 @@ def test_nodal_eqv_stress(mapdl, static_solve): @staticmethod @requires("ansys-tools-visualization_interface") - def test_plot_nodal_eqv_stress(mapdl, static_solve, verify_image_cache): + def test_plot_nodal_eqv_stress(mapdl, resume, verify_image_cache): verify_image_cache.skip = True # skipping image verification assert mapdl.post_processing.plot_nodal_eqv_stress(smooth_shading=True) is None @staticmethod - def test_node_selection(mapdl, static_solve): + def test_node_selection(mapdl, resume): mapdl.nsel("S", "NODE", vmin=1, vmax=2000, mute=True) assert mapdl.post_processing.selected_nodes.sum() == 2000 @@ -250,7 +259,7 @@ def test_node_selection(mapdl, static_solve): assert mapdl.post_processing.selected_nodes.sum() == mapdl.mesh.n_node @staticmethod - def test_element_selection(mapdl, static_solve): + def test_element_selection(mapdl, resume): mx_val = 1000 mapdl.esel("S", "ELEM", vmin=1, vmax=mx_val, mute=True) assert mapdl.post_processing.selected_elements.sum() == mx_val @@ -261,7 +270,7 @@ def test_element_selection(mapdl, static_solve): # TODO: add valid result @staticmethod @pytest.mark.parametrize("comp", ["X", "Y", "z", "all"]) # lowercase intentional - def test_rot(mapdl, static_solve, comp): + def test_rot(mapdl, resume, comp): from_grpc = mapdl.post_processing.nodal_rotation(comp) # need a result with ROTX DOF @@ -276,7 +285,7 @@ def test_rot(mapdl, static_solve, comp): @staticmethod @requires("ansys-tools-visualization_interface") @pytest.mark.parametrize("comp", ["X", "Y", "z", "all"]) # lowercase intentional - def test_plot_rot(mapdl, static_solve, comp): + def test_plot_rot(mapdl, resume, comp): if comp == "all": context = pytest.raises( ValueError, match='"ALL" not allowed in this context' @@ -289,13 +298,13 @@ def test_plot_rot(mapdl, static_solve, comp): # TODO: add valid result @staticmethod - def test_temperature(mapdl, static_solve): + def test_temperature(mapdl, resume): from_grpc = mapdl.post_processing.nodal_temperature() assert np.allclose(from_grpc, 0) # TODO: add valid result @staticmethod - def test_element_temperature(mapdl, static_solve): + def test_element_temperature(mapdl, resume): mapdl.post1(mute=True) mapdl.set(1, 1, mute=True) values = mapdl.post_processing.element_temperature() @@ -303,40 +312,40 @@ def test_element_temperature(mapdl, static_solve): @staticmethod @requires("ansys-tools-visualization_interface") - def test_plot_element_temperature(mapdl, static_solve): + def test_plot_element_temperature(mapdl, resume): mapdl.set(1, 1, mute=True) assert mapdl.post_processing.plot_element_temperature() is None @staticmethod @requires("ansys-tools-visualization_interface") - def test_plot_temperature(mapdl, static_solve): + def test_plot_temperature(mapdl, resume): assert mapdl.post_processing.plot_nodal_temperature() is None # TODO: add valid result @staticmethod - def test_pressure(mapdl, static_solve): + def test_pressure(mapdl, resume): from_grpc = mapdl.post_processing.nodal_pressure() assert np.allclose(from_grpc, 0) @staticmethod @requires("ansys-tools-visualization_interface") - def test_plot_pressure(mapdl, static_solve): + def test_plot_pressure(mapdl, resume): assert mapdl.post_processing.plot_nodal_pressure() is None # TODO: add valid result @staticmethod - def test_voltage(mapdl, static_solve): + def test_voltage(mapdl, resume): from_grpc = mapdl.post_processing.nodal_voltage() assert np.allclose(from_grpc, 0) @staticmethod @requires("ansys-tools-visualization_interface") - def test_plot_voltage(mapdl, static_solve): + def test_plot_voltage(mapdl, resume): assert mapdl.post_processing.plot_nodal_voltage() is None @staticmethod @pytest.mark.parametrize("comp", COMPONENT_STRESS_TYPE) - def test_nodal_component_stress(mapdl, static_solve, comp): + def test_nodal_component_stress(mapdl, resume, comp): from_grpc = mapdl.post_processing.nodal_component_stress(comp) mapdl.post1(mute=True) mapdl.set(1, 1, mute=True) @@ -353,12 +362,12 @@ def test_nodal_component_stress(mapdl, static_solve, comp): @staticmethod @requires("ansys-tools-visualization_interface") - def test_plot_nodal_component_stress(mapdl, static_solve): + def test_plot_nodal_component_stress(mapdl, resume): assert mapdl.post_processing.plot_nodal_component_stress("X") is None @staticmethod @pytest.mark.parametrize("comp", PRINCIPAL_TYPE) - def test_nodal_principal_stress(mapdl, static_solve, comp): + def test_nodal_principal_stress(mapdl, resume, comp): from_grpc = mapdl.post_processing.nodal_principal_stress(comp) mapdl.post1(mute=True) mapdl.set(1, 1, mute=True) @@ -371,15 +380,15 @@ def test_nodal_principal_stress(mapdl, static_solve, comp): # grpc includes all nodes. ignore the ones not included in prnsol from_grpc = from_grpc[np.in1d(mapdl.mesh.nnum, nnum_ans)] - assert np.allclose(from_grpc, from_prns) + assert np.allclose(from_grpc, from_prns, 1e-5) @staticmethod @requires("ansys-tools-visualization_interface") - def test_plot_nodal_principal_stress(mapdl, static_solve): + def test_plot_nodal_principal_stress(mapdl, resume): assert mapdl.post_processing.plot_nodal_principal_stress(1) is None @staticmethod - def test_nodal_stress_intensity(mapdl, static_solve): + def test_nodal_stress_intensity(mapdl, resume): mapdl.post1(mute=True) mapdl.set(1, 1, mute=True) @@ -387,19 +396,19 @@ def test_nodal_stress_intensity(mapdl, static_solve): data = np.genfromtxt(mapdl.prnsol("S", "PRIN").splitlines()[1:]) nnum_ans = data[:, 0].astype(np.int32) sint_ans = data[:, -2] - sint = mapdl.post_processing.nodal_stress_intensity + sint = mapdl.post_processing.nodal_stress_intensity() sint_aligned = sint[np.in1d(mapdl.mesh.nnum, nnum_ans)] assert np.allclose(sint_ans, sint_aligned) @staticmethod @requires("ansys-tools-visualization_interface") - def test_plot_nodal_stress_intensity(mapdl, static_solve): + def test_plot_nodal_stress_intensity(mapdl, resume): assert mapdl.post_processing.plot_nodal_stress_intensity() is None @staticmethod @pytest.mark.parametrize("comp", COMPONENT_STRESS_TYPE) - def test_nodal_total_component_strain(mapdl, static_solve, comp): + def test_nodal_total_component_strain(mapdl, resume, comp): mapdl.post1(mute=True) mapdl.set(1, 1, mute=True) @@ -416,12 +425,12 @@ def test_nodal_total_component_strain(mapdl, static_solve, comp): @staticmethod @requires("ansys-tools-visualization_interface") - def test_plot_nodal_total_component_strain(mapdl, static_solve): + def test_plot_nodal_total_component_strain(mapdl, resume): assert mapdl.post_processing.plot_nodal_total_component_strain("x") is None @staticmethod @pytest.mark.parametrize("comp", PRINCIPAL_TYPE) - def test_nodal_principal_total_strain(mapdl, static_solve, comp): + def test_nodal_principal_total_strain(mapdl, resume, comp): from_grpc = mapdl.post_processing.nodal_total_principal_strain(comp) mapdl.post1(mute=True) mapdl.set(1, 1, mute=True) @@ -438,11 +447,11 @@ def test_nodal_principal_total_strain(mapdl, static_solve, comp): @staticmethod @requires("ansys-tools-visualization_interface") - def test_plot_nodal_principal_total_strain(mapdl, static_solve): + def test_plot_nodal_principal_total_strain(mapdl, resume): assert mapdl.post_processing.plot_nodal_total_principal_strain(1) is None @staticmethod - def test_nodal_total_strain_intensity(mapdl, static_solve): + def test_nodal_total_strain_intensity(mapdl, resume): mapdl.post1(mute=True) mapdl.set(1, 1, mute=True) @@ -457,11 +466,11 @@ def test_nodal_total_strain_intensity(mapdl, static_solve): @staticmethod @requires("ansys-tools-visualization_interface") - def test_plot_nodal_total_strain_intensity(mapdl, static_solve): + def test_plot_nodal_total_strain_intensity(mapdl, resume): assert mapdl.post_processing.plot_nodal_total_strain_intensity() is None @staticmethod - def test_nodal_total_eqv_strain(mapdl, static_solve): + def test_nodal_total_eqv_strain(mapdl, resume): mapdl.post1(mute=True) mapdl.set(1, 1, mute=True) @@ -476,7 +485,7 @@ def test_nodal_total_eqv_strain(mapdl, static_solve): @staticmethod @requires("ansys-tools-visualization_interface") - def test_plot_nodal_total_eqv_strain(mapdl, static_solve): + def test_plot_nodal_total_eqv_strain(mapdl, resume): assert ( mapdl.post_processing.plot_nodal_total_eqv_strain(smooth_shading=True) is None @@ -485,69 +494,7 @@ def test_plot_nodal_total_eqv_strain(mapdl, static_solve): ############################################################################### @staticmethod @pytest.mark.parametrize("comp", COMPONENT_STRESS_TYPE) - def test_nodal_component_stress(mapdl, static_solve, comp): - from_grpc = mapdl.post_processing.nodal_component_stress(comp) - mapdl.post1(mute=True) - mapdl.set(1, 1, mute=True) - index = COMPONENT_STRESS_TYPE.index(comp) - mapdl.prnsol("S", "COMP") # flush to ignore warning - arr = np.genfromtxt(mapdl.prnsol("S", "COMP").splitlines()[1:]) - nnum_ans = arr[:, 0] - from_prns = arr[:, index + 1] - - # grpc includes all nodes. ignore the ones not included in prnsol - from_grpc = from_grpc[np.in1d(mapdl.mesh.nnum, nnum_ans)] - - assert np.allclose(from_grpc, from_prns) - - @staticmethod - @requires("ansys-tools-visualization_interface") - def test_plot_nodal_component_stress(mapdl, static_solve): - assert mapdl.post_processing.plot_nodal_component_stress("X") is None - - @staticmethod - @pytest.mark.parametrize("comp", PRINCIPAL_TYPE) - def test_nodal_principal_stress(mapdl, static_solve, comp): - from_grpc = mapdl.post_processing.nodal_principal_stress(comp) - mapdl.post1(mute=True) - mapdl.set(1, 1, mute=True) - index = PRINCIPAL_TYPE.index(comp) - mapdl.prnsol("S", "PRIN") # flush to ignore warning - arr = np.genfromtxt(mapdl.prnsol("S", "PRIN").splitlines()[1:]) - nnum_ans = arr[:, 0] - from_prns = arr[:, index + 1] - - # grpc includes all nodes. ignore the ones not included in prnsol - from_grpc = from_grpc[np.in1d(mapdl.mesh.nnum, nnum_ans)] - assert np.allclose(from_grpc, from_prns, atol=1e-5) - - @staticmethod - @requires("ansys-tools-visualization_interface") - def test_plot_nodal_principal_stress(mapdl, static_solve): - assert mapdl.post_processing.plot_nodal_principal_stress(1) is None - - @staticmethod - def test_nodal_stress_intensity(mapdl, static_solve): - mapdl.post1(mute=True) - mapdl.set(1, 1, mute=True) - - mapdl.prnsol("S", "PRIN", mute=True) # run twice to clear out warning - data = np.genfromtxt(mapdl.prnsol("S", "PRIN").splitlines()[1:]) - nnum_ans = data[:, 0].astype(np.int32) - sint_ans = data[:, -2] - sint = mapdl.post_processing.nodal_stress_intensity() - - sint_aligned = sint[np.in1d(mapdl.mesh.nnum, nnum_ans)] - assert np.allclose(sint_ans, sint_aligned) - - @staticmethod - @requires("ansys-tools-visualization_interface") - def test_plot_nodal_stress_intensity(mapdl, static_solve): - assert mapdl.post_processing.plot_nodal_stress_intensity() is None - - @staticmethod - @pytest.mark.parametrize("comp", COMPONENT_STRESS_TYPE) - def test_nodal_elastic_component_strain(mapdl, static_solve, comp): + def test_nodal_elastic_component_strain(mapdl, resume, comp): mapdl.post1(mute=True) mapdl.set(1, 1, mute=True) @@ -564,12 +511,12 @@ def test_nodal_elastic_component_strain(mapdl, static_solve, comp): @staticmethod @requires("ansys-tools-visualization_interface") - def test_plot_nodal_elastic_component_strain(mapdl, static_solve): + def test_plot_nodal_elastic_component_strain(mapdl, resume): assert mapdl.post_processing.plot_nodal_elastic_component_strain("x") is None @staticmethod @pytest.mark.parametrize("comp", PRINCIPAL_TYPE) - def test_nodal_elastic_principal_strain(mapdl, static_solve, comp): + def test_nodal_elastic_principal_strain(mapdl, resume, comp): from_grpc = mapdl.post_processing.nodal_elastic_principal_strain(comp) mapdl.post1(mute=True) mapdl.set(1, 1, mute=True) @@ -586,11 +533,11 @@ def test_nodal_elastic_principal_strain(mapdl, static_solve, comp): @staticmethod @requires("ansys-tools-visualization_interface") - def test_plot_nodal_elastic_principal_strain(mapdl, static_solve): + def test_plot_nodal_elastic_principal_strain(mapdl, resume): assert mapdl.post_processing.plot_nodal_elastic_principal_strain(1) is None @staticmethod - def test_nodal_elastic_strain_intensity(mapdl, static_solve): + def test_nodal_elastic_strain_intensity(mapdl, resume): mapdl.post1(mute=True) mapdl.set(1, 1, mute=True) @@ -605,11 +552,11 @@ def test_nodal_elastic_strain_intensity(mapdl, static_solve): @staticmethod @requires("ansys-tools-visualization_interface") - def test_plot_nodal_elastic_strain_intensity(mapdl, static_solve): + def test_plot_nodal_elastic_strain_intensity(mapdl, resume): assert mapdl.post_processing.plot_nodal_elastic_strain_intensity() is None @staticmethod - def test_nodal_elastic_eqv_strain(mapdl, static_solve): + def test_nodal_elastic_eqv_strain(mapdl, resume): mapdl.post1(mute=True) mapdl.set(1, 1, mute=True) @@ -624,7 +571,7 @@ def test_nodal_elastic_eqv_strain(mapdl, static_solve): @staticmethod @requires("ansys-tools-visualization_interface") - def test_plot_nodal_elastic_eqv_strain(mapdl, static_solve): + def test_plot_nodal_elastic_eqv_strain(mapdl, resume): assert ( mapdl.post_processing.plot_nodal_elastic_eqv_strain(smooth_shading=True) is None @@ -632,7 +579,7 @@ def test_plot_nodal_elastic_eqv_strain(mapdl, static_solve): @staticmethod @pytest.mark.parametrize("comp", ["X", "Y", "z", "all"]) # lowercase intentional - def test_elem_disp(mapdl, static_solve, comp): + def test_elem_disp(mapdl, resume, comp): mapdl.post1(mute=True) mapdl.set(1, 1, mute=True) mapdl.allsel() @@ -657,7 +604,7 @@ def test_elem_disp(mapdl, static_solve, comp): @staticmethod @pytest.mark.parametrize("option", ["min", "max", "avg"]) - def test_elem_disp_all(mapdl, static_solve, option): + def test_elem_disp_all(mapdl, resume, option): mapdl.post1(mute=True) mapdl.set(1, 1, mute=True) @@ -675,7 +622,7 @@ def test_elem_disp_all(mapdl, static_solve, option): assert np.allclose(array, disp_from_grpc) @staticmethod - def test_elem_disp_norm(mapdl, static_solve): + def test_elem_disp_norm(mapdl, resume): mapdl.post1(mute=True) mapdl.set(1, 1, mute=True) disp = mapdl.post_processing.element_displacement("ALL") @@ -686,7 +633,7 @@ def test_elem_disp_norm(mapdl, static_solve): @staticmethod @pytest.mark.parametrize("comp", ["X", "Y", "Z", "NORM", "all"]) @requires("ansys-tools-visualization_interface") - def test_elem_disp_plot(mapdl, static_solve, comp): + def test_elem_disp_plot(mapdl, resume, comp): mapdl.post1(mute=True) mapdl.set(1, 1, mute=True) @@ -705,7 +652,7 @@ def test_elem_disp_plot(mapdl, static_solve, comp): @staticmethod @pytest.mark.parametrize("component", STRESS_TYPES) @pytest.mark.parametrize("option", ["min", "max", "avg"]) - def test_element_stress(mapdl, static_solve, component, option): + def test_element_stress(mapdl, resume, component, option): mapdl.post1(mute=True) mapdl.set(1, 1, mute=True) stress = mapdl.post_processing.element_stress(component, option) @@ -719,14 +666,14 @@ def test_element_stress(mapdl, static_solve, component, option): @staticmethod @pytest.mark.parametrize("comp", ["X", "1", "INT", "EQV"]) @requires("ansys-tools-visualization_interface") - def test_plot_element_stress(mapdl, static_solve, comp): + def test_plot_element_stress(mapdl, resume, comp): mapdl.post1(mute=True) mapdl.set(1, 1, mute=True) assert mapdl.post_processing.plot_element_stress(comp) is None @staticmethod @requires("ansys-tools-visualization_interface") - def test_plot_element_values(mapdl, static_solve, verify_image_cache): + def test_plot_element_values(mapdl, resume, verify_image_cache): verify_image_cache.high_variance_test = 600 mapdl.post1(mute=True) mapdl.set(1, 1, mute=True) @@ -734,7 +681,7 @@ def test_plot_element_values(mapdl, static_solve, verify_image_cache): @staticmethod @requires("ansys-tools-visualization_interface") - def test_general_plotter_returns(mapdl, static_solve, verify_image_cache): + def test_general_plotter_returns(mapdl, resume, verify_image_cache): verify_image_cache.skip = True # skipping image verification # Returns @@ -796,23 +743,36 @@ def test_general_plotter_returns(mapdl, static_solve, verify_image_cache): ############################################################################### -class Test_plastic_solve: +class Test_plastic_solve(TestClass): @staticmethod @pytest.fixture(scope="class") def plastic_solve(mapdl): mapdl.mute = True - mapdl.finish() - mapdl.clear() mapdl.input(examples.verif_files.vmfiles["vm273"]) + mapdl.mute = False + + mapdl.save("plastic_solve", slab="all") + + @staticmethod + @pytest.fixture(scope="function") + def resume(mapdl, plastic_solve): + mapdl.prep7() + mapdl.resume("plastic_solve") + + mapdl.allsel() mapdl.post1() mapdl.set(1, 2) - mapdl.mute = False + + # necessary for any prnsol printouts + mapdl.header("off", "off", "off", "off", "off", "off") + nsigfig = 10 + mapdl.format("", "E", nsigfig + 9, nsigfig) @staticmethod @pytest.mark.parametrize("comp", COMPONENT_STRESS_TYPE) - def test_nodal_plastic_component_strain(mapdl, plastic_solve, comp): + def test_nodal_plastic_component_strain(mapdl, resume, comp): index = COMPONENT_STRESS_TYPE.index(comp) mapdl.prnsol("EPPL", "COMP", mute=True) # run twice to clear out warning @@ -826,12 +786,12 @@ def test_nodal_plastic_component_strain(mapdl, plastic_solve, comp): @staticmethod @requires("ansys-tools-visualization_interface") - def test_plot_nodal_plastic_component_strain(mapdl, plastic_solve): + def test_plot_nodal_plastic_component_strain(mapdl, resume): assert mapdl.post_processing.plot_nodal_plastic_component_strain("x") is None @staticmethod @pytest.mark.parametrize("comp", PRINCIPAL_TYPE) - def test_nodal_plastic_principal_strain(mapdl, plastic_solve, comp): + def test_nodal_plastic_principal_strain(mapdl, resume, comp): from_grpc = mapdl.post_processing.nodal_plastic_principal_strain(comp) index = PRINCIPAL_TYPE.index(comp) @@ -847,11 +807,11 @@ def test_nodal_plastic_principal_strain(mapdl, plastic_solve, comp): @staticmethod @requires("ansys-tools-visualization_interface") - def test_plot_nodal_plastic_principal_strain(mapdl, plastic_solve): + def test_plot_nodal_plastic_principal_strain(mapdl, resume): assert mapdl.post_processing.plot_nodal_plastic_principal_strain(1) is None @staticmethod - def test_nodal_plastic_strain_intensity(mapdl, plastic_solve): + def test_nodal_plastic_strain_intensity(mapdl, resume): mapdl.prnsol("EPPL", "PRIN", mute=True) # run twice to clear out warning data = np.genfromtxt(mapdl.prnsol("EPPL", "PRIN").splitlines()[1:]) nnum_ans = data[:, 0].astype(np.int32) @@ -863,11 +823,11 @@ def test_nodal_plastic_strain_intensity(mapdl, plastic_solve): @staticmethod @requires("ansys-tools-visualization_interface") - def test_plot_nodal_plastic_strain_intensity(mapdl, plastic_solve): + def test_plot_nodal_plastic_strain_intensity(mapdl, resume): assert mapdl.post_processing.plot_nodal_plastic_strain_intensity() is None @staticmethod - def test_nodal_plastic_eqv_strain(mapdl, plastic_solve): + def test_nodal_plastic_eqv_strain(mapdl, resume): mapdl.prnsol("EPPL", "PRIN", mute=True) # run twice to clear out warning data = np.genfromtxt(mapdl.prnsol("EPPL", "PRIN").splitlines()[1:]) nnum_ans = data[:, 0].astype(np.int32) @@ -879,24 +839,19 @@ def test_nodal_plastic_eqv_strain(mapdl, plastic_solve): @staticmethod @requires("ansys-tools-visualization_interface") - def test_plot_nodal_plastic_eqv_strain(mapdl, plastic_solve): + def test_plot_nodal_plastic_eqv_strain(mapdl, resume): assert ( mapdl.post_processing.plot_nodal_plastic_eqv_strain(smooth_shading=True) is None ) -class Test_contact_solve: +class Test_contact_solve(TestClass): @staticmethod @pytest.fixture(scope="class") def contact_solve(mapdl): - mapdl.mute = True - mapdl.finish() - mapdl.clear() - # Based on tech demo 28. - mapdl.prep7() # ***** Problem parameters ******** l = 76.2e-03 / 3 # Length of each plate,m w = 31.75e-03 / 2 # Width of each plate,m @@ -1166,14 +1121,12 @@ def contact_solve(mapdl): mapdl.d(1, "all") mapdl.ddele(1, "temp") mapdl.allsel("all") - mapdl.mute = False # ========================================================== # * Solution # ========================================================== # from precedent fixture uz1 = 3.18e-03 / 4000 - mapdl.mute = False mapdl.run("/solu") mapdl.antype(4) # Transient analysis mapdl.lnsrch("on") @@ -1191,30 +1144,38 @@ def contact_solve(mapdl): mapdl.allsel() mapdl.solve() + mapdl.save("contact_solve", slab="all") + + @staticmethod + @pytest.fixture(scope="function") + def resume(mapdl, contact_solve): + mapdl.prep7() + mapdl.resume("contact_solve") mapdl.post1() mapdl.allsel() mapdl.set("last") - mapdl.mute = False + + # Format tables. + mapdl.header("OFF", "OFF", "OFF", "OFF", "OFF", "OFF") + nsigfig = 10 + mapdl.format("", "E", nsigfig + 9, nsigfig) + mapdl.page(1e9, "", -1, 240) @staticmethod - def test_time(mapdl, contact_solve): + def test_time(mapdl, resume): assert mapdl.post_processing.time == 1 @staticmethod - def test_freq(mapdl, contact_solve): + def test_freq(mapdl, resume): # same as post_processing.time + mapdl.set("last") + assert mapdl.post_processing.freq == 1 assert mapdl.post_processing.time == mapdl.post_processing.freq @staticmethod - def test_nodal_contact_friction_stress(mapdl, contact_solve): + def test_nodal_contact_friction_stress(mapdl, resume): # Format tables. - mapdl.post1() - mapdl.header("OFF", "OFF", "OFF", "OFF", "OFF", "OFF") - nsigfig = 10 - mapdl.format("", "E", nsigfig + 9, nsigfig) - mapdl.page(1e9, "", -1, 240) - prnsol = mapdl.prnsol("CONT") array = np.genfromtxt(prnsol.splitlines(), skip_header=1) sfric_prn = array[:, 4] @@ -1227,7 +1188,7 @@ def test_nodal_contact_friction_stress(mapdl, contact_solve): @staticmethod @requires("ansys-tools-visualization_interface") - def test_plot_nodal_contact_friction_stress(mapdl, contact_solve): + def test_plot_nodal_contact_friction_stress(mapdl, resume): assert ( mapdl.post_processing.plot_nodal_contact_friction_stress( smooth_shading=True @@ -1237,7 +1198,7 @@ def test_plot_nodal_contact_friction_stress(mapdl, contact_solve): @staticmethod @requires("ansys-tools-visualization_interface") - def test_plot_incomplete_element_selection(mapdl, contact_solve): + def test_plot_incomplete_element_selection(mapdl, resume): mapdl.esel("S", "ELEM", "", 1, mapdl.mesh.n_elem // 2) assert mapdl.post_processing.plot_element_displacement() is None @@ -1257,7 +1218,7 @@ def test_plot_incomplete_element_selection(mapdl, contact_solve): @staticmethod @requires("ansys-tools-visualization_interface") - def test_plot_incomplete_nodal_selection(mapdl, contact_solve, verify_image_cache): + def test_plot_incomplete_nodal_selection(mapdl, resume, verify_image_cache): verify_image_cache.skip = True mapdl.nsel("S", "NODE", "", 1, mapdl.mesh.n_node // 2) @@ -1280,21 +1241,21 @@ def test_plot_incomplete_nodal_selection(mapdl, contact_solve, verify_image_cach assert mapdl.post_processing.plot_nodal_displacement() is None @staticmethod - def test_time_frequency_values(mapdl, contact_solve): + def test_time_frequency_values(mapdl, resume): assert np.allclose( mapdl.post_processing.time_values, mapdl.post_processing.frequency_values, ) @staticmethod - def test_time_values(mapdl, contact_solve): + def test_time_values(mapdl, resume): assert np.allclose( mapdl.post_processing.time_values, np.array([0.2, 0.4, 0.7, 1.0]) ) @staticmethod @pytest.mark.parametrize("step_", [1, 2, 3, 4]) - def test_set(mapdl, contact_solve, step_): + def test_set(mapdl, resume, step_): mapdl.set(nset=step_) assert mapdl.post_processing.step == step_ @@ -1355,7 +1316,7 @@ def test_cuadratic_beam(mapdl, cuadratic_beam_problem): ) -def test_exited(mapdl): +def test_exited(mapdl, cleared): mapdl._exited = True with pytest.raises(MapdlRuntimeError): mapdl.post_processing.plot_nodal_displacement( diff --git a/tests/test_solution.py b/tests/test_solution.py index 731e805b33..985a0939fb 100644 --- a/tests/test_solution.py +++ b/tests/test_solution.py @@ -26,125 +26,125 @@ from ansys.mapdl.core.errors import MapdlRuntimeError -def time_step_size(mapdl): +def test_time_step_size(mapdl, cleared): assert isinstance(mapdl.solution.time_step_size, float) -def test_n_cmls(mapdl): +def test_n_cmls(mapdl, cleared): assert isinstance(mapdl.solution.n_cmls, float) -def test_n_cmss(mapdl): +def test_n_cmss(mapdl, cleared): assert isinstance(mapdl.solution.n_cmss, float) -def test_n_eqit(mapdl): +def test_n_eqit(mapdl, cleared): assert isinstance(mapdl.solution.n_eqit, float) -def test_n_cmit(mapdl): +def test_n_cmit(mapdl, cleared): assert isinstance(mapdl.solution.n_cmit, float) -def test_converged(mapdl): +def test_converged(mapdl, cleared): assert isinstance(mapdl.solution.converged, bool) -def test_mx_dof(mapdl): +def test_mx_dof(mapdl, cleared): assert isinstance(mapdl.solution.mx_dof, float) -def test_res_frq(mapdl): +def test_res_frq(mapdl, cleared): assert isinstance(mapdl.solution.res_frq, float) -def test_res_eig(mapdl): +def test_res_eig(mapdl, cleared): assert isinstance(mapdl.solution.res_eig, float) -def test_decent_parm(mapdl): +def test_decent_parm(mapdl, cleared): assert isinstance(mapdl.solution.decent_parm, float) -def test_force_cnv(mapdl): +def test_force_cnv(mapdl, cleared): assert isinstance(mapdl.solution.force_cnv, float) -def test_moment_cnv(mapdl): +def test_moment_cnv(mapdl, cleared): assert isinstance(mapdl.solution.moment_cnv, float) -def test_heat_flow_cnv(mapdl): +def test_heat_flow_cnv(mapdl, cleared): assert isinstance(mapdl.solution.heat_flow_cnv, float) -def test_magnetic_flux_cnv(mapdl): +def test_magnetic_flux_cnv(mapdl, cleared): assert isinstance(mapdl.solution.magnetic_flux_cnv, float) -def test_current_segment_cnv(mapdl): +def test_current_segment_cnv(mapdl, cleared): assert isinstance(mapdl.solution.current_segment_cnv, float) -def test_current_cnv(mapdl): +def test_current_cnv(mapdl, cleared): assert isinstance(mapdl.solution.current_cnv, float) -def test_fluid_flow_cnv(mapdl): +def test_fluid_flow_cnv(mapdl, cleared): assert isinstance(mapdl.solution.fluid_flow_cnv, float) -def test_displacement_cnv(mapdl): +def test_displacement_cnv(mapdl, cleared): assert isinstance(mapdl.solution.displacement_cnv, float) -def test_rotation_cnv(mapdl): +def test_rotation_cnv(mapdl, cleared): assert isinstance(mapdl.solution.rotation_cnv, float) -def test_temperature_cnv(mapdl): +def test_temperature_cnv(mapdl, cleared): assert isinstance(mapdl.solution.temperature_cnv, float) -def test_vector_cnv(mapdl): +def test_vector_cnv(mapdl, cleared): assert isinstance(mapdl.solution.vector_cnv, float) -def test_smcv(mapdl): +def test_smcv(mapdl, cleared): assert isinstance(mapdl.solution.smcv, float) -def test_voltage_conv(mapdl): +def test_voltage_conv(mapdl, cleared): assert isinstance(mapdl.solution.voltage_conv, float) -def test_pressure_conv(mapdl): +def test_pressure_conv(mapdl, cleared): assert isinstance(mapdl.solution.pressure_conv, float) -def test_velocity_conv(mapdl): +def test_velocity_conv(mapdl, cleared): assert isinstance(mapdl.solution.velocity_conv, float) -def test_mx_creep_rat(mapdl): +def test_mx_creep_rat(mapdl, cleared): assert isinstance(mapdl.solution.mx_creep_rat, float) -def test_mx_plastic_inc(mapdl): +def test_mx_plastic_inc(mapdl, cleared): assert isinstance(mapdl.solution.mx_plastic_inc, float) -def test_n_cg_iter(mapdl): +def test_n_cg_iter(mapdl, cleared): assert isinstance(mapdl.solution.n_cg_iter, float) -def test_solution_call(mapdl): +def test_solution_call(mapdl, cleared): mapdl.finish() output = mapdl.solution() assert "MAPDL SOLUTION ROUTINE" in output or "ANSYS SOLUTION ROUTINE" in output -def test_exited(mapdl): +def test_exited(mapdl, cleared): mapdl._exited = True with pytest.raises(MapdlRuntimeError): parm = mapdl.solution.time_step_size diff --git a/tests/test_xpl.py b/tests/test_xpl.py index 467a101976..6c85f14e53 100644 --- a/tests/test_xpl.py +++ b/tests/test_xpl.py @@ -85,7 +85,7 @@ def test_save(xpl): xpl.list() -def test_copy(mapdl, xpl): +def test_copy(mapdl, cleared, xpl): filename = "tmpfile.full" xpl.copy(filename) assert filename in mapdl.list_files()