Skip to content

Commit dd2c3c2

Browse files
refactor: removing warnings (#3763)
* fix: removing some warnings * refactor: using isin * test: raising warnings * chore: adding changelog file 3763.added.md [dependabot-skip] * fix: update regex pattern in logging tests for consistency * fix: console arg in pytest cli * fix: more warnings * fix: marker * test: removing dpf * refactor: small refactor of warnings. * fix: killing started processes during testing * fix: killing started processes during testing * feat: removing warning flag * revert: "test: removing dpf" This reverts commit ace806a. * fix: tests * fix: warnings * fix: conftest * refactor: pytest mark. Removing only-gui --------- Co-authored-by: pyansys-ci-bot <[email protected]>
1 parent 8725a6d commit dd2c3c2

File tree

18 files changed

+157
-95
lines changed

18 files changed

+157
-95
lines changed

doc/changelog.d/3763.added.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
refactor: removing warnings

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ pymapdl = "ansys.mapdl.core.cli:main"
123123
addopts = "-rxXsa -vvv --maxfail=10 --random-order-bucket=class --random-order --durations=10 --timeout=180"
124124
junit_family = "legacy"
125125
filterwarnings = [
126+
"ignore::ResourceWarning",
126127
"ignore::FutureWarning",
127128
"ignore::PendingDeprecationWarning",
128129
"ignore::DeprecationWarning",
@@ -134,7 +135,9 @@ filterwarnings = [
134135
markers = [
135136
"skip_grpc: skip tests using grpc",
136137
"gui: skip tests that launch the GUI interface",
138+
"console: Run also console tests",
137139
]
140+
138141
testpaths = "tests"
139142
image_cache_dir = "tests/.image_cache"
140143
# Output logging records as they are emitted directly into the console

src/ansys/mapdl/core/launcher.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ def get_process_at_port(port) -> Optional[psutil.Process]:
306306
for proc in psutil.process_iter():
307307
try:
308308
# just to check if we can access the port
309-
connections = proc.connections()
309+
connections = proc.net_connections()
310310
except psutil.AccessDenied:
311311
continue
312312
except psutil.NoSuchProcess:

src/ansys/mapdl/core/mapdl_core.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2942,7 +2942,9 @@ def _raise_output_errors(self, response):
29422942

29432943
# Raising errors
29442944
if error_is_fine:
2945-
self._log.warn("PERMITTED ERROR: " + permited_error_message.string)
2945+
self._log.warning(
2946+
"PERMITTED ERROR: " + permited_error_message.string
2947+
)
29462948
continue
29472949
else:
29482950
# We don't need to log exception because they already included in the main logger.

src/ansys/mapdl/core/mapdl_grpc.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2546,7 +2546,7 @@ def _download_from_remote(
25462546

25472547
else:
25482548
raise ValueError(
2549-
f"The `file` parameter type ({type(files)}) is not supported."
2549+
f"The `file` parameter type ({type(files)}) is not supported. "
25502550
"Only strings, tuple of strings or list of strings are allowed."
25512551
)
25522552

@@ -2651,9 +2651,10 @@ def _download(
26512651
)
26522652

26532653
if not file_size:
2654-
warn(
2655-
f'File "{target_name}" is empty or does not exist in {self.list_files()}.'
2656-
)
2654+
if target_name not in self.list_files():
2655+
warn(f'File "{target_name}" does not exist.')
2656+
else:
2657+
warn(f'File "{target_name}" is empty.')
26572658

26582659
@protect_grpc
26592660
def upload(self, file_name: str, progress_bar: bool = _HAS_TQDM) -> str:

tests/conftest.py

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,9 @@ def requires(requirement: str):
168168
elif "console" == requirement:
169169
return pytest.mark.console
170170

171+
elif "gui" == requirement:
172+
return pytest.mark.gui
173+
171174
else:
172175
return requires_dependency(requirement)
173176

@@ -338,25 +341,28 @@ def pytest_addoption(parser):
338341
"--console",
339342
action="store_true",
340343
default=False,
344+
dest="console",
341345
help="run console tests",
342346
)
343-
parser.addoption("--gui", action="store_true", default=False, help="run GUI tests")
344347
parser.addoption(
345-
"--only-gui",
346-
action="store_true",
347-
default=False,
348-
help="run only GUI tests",
348+
"--gui", action="store_true", default=False, dest="gui", help="run GUI tests"
349349
)
350350

351351

352-
def pytest_collection_modifyitems(config, items):
352+
def pytest_collection_modifyitems(session, config, items):
353353
if not config.getoption("--console"):
354354
# --console given in cli: run console interface tests
355355
skip_console = pytest.mark.skip(reason="need --console option to run")
356356
for item in items:
357357
if "console" in item.keywords:
358358
item.add_marker(skip_console)
359359

360+
if not config.getoption("--gui"):
361+
skip_gui = pytest.mark.skip(reason="need --gui option to run")
362+
for item in items:
363+
if "gui" in item.keywords:
364+
item.add_marker(skip_gui)
365+
360366
if not HAS_GRPC:
361367
skip_grpc = pytest.mark.skip(
362368
reason="Requires gRPC connection (at least v211 to run)"
@@ -365,21 +371,6 @@ def pytest_collection_modifyitems(config, items):
365371
if "skip_grpc" in item.keywords:
366372
item.add_marker(skip_grpc)
367373

368-
only_gui_filter = config.getoption("--only-gui")
369-
if only_gui_filter:
370-
new_items = []
371-
for item in items:
372-
mark = item.get_closest_marker("requires_gui")
373-
if mark and mark.name == "requires_gui":
374-
new_items.append(item)
375-
items[:] = new_items
376-
377-
if not config.getoption("--gui") and not only_gui_filter:
378-
skip_gui = pytest.mark.skip(reason="Requires to launch MAPDL GUI interface.")
379-
for item in items:
380-
if "requires_gui" in item.keywords:
381-
item.add_marker(skip_gui)
382-
383374

384375
################################################################
385376
#
@@ -670,6 +661,7 @@ def _patch_method(method):
670661
(_patch_method("_subscribe_to_channel"), _returns("")),
671662
(_patch_method("_run_at_connect"), _returns("")),
672663
(_patch_method("_exit_mapdl"), _returns(None)),
664+
(_patch_method("kill_job"), _returns(None)),
673665
(
674666
_patch_method("_check_mapdl_os"),
675667
_returns("linux" if os.name == "posix" else "win"),

tests/test_cli.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,7 @@ def make_fake_process(pid, name, port=PORT1, ansys_process=False, n_children=0):
5757
return mock_process
5858

5959

60-
@pytest.fixture
61-
@requires("click")
62-
@requires("nostudent")
60+
@pytest.fixture(scope="function")
6361
def run_cli():
6462
def do_run(arguments=""):
6563
from click.testing import CliRunner
@@ -373,6 +371,9 @@ def test_convert_pipe(output):
373371
assert "Script generated by ansys-mapdl-core version" in stdout
374372
assert "mapdl.exit()" in stdout
375373

374+
process_pymapdl.kill()
375+
process_echo.kill()
376+
376377

377378
DEFAULT_ARGS = {
378379
"apdl_strings": "/prep7\nBLOCK,0,1,0,1,0,1",

tests/test_commands.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
StringWithLiteralRepr,
3737
)
3838
from ansys.mapdl.core.examples.verif_files import vmfiles
39-
from conftest import TestClass, has_dependency, requires
39+
from conftest import NullContext, TestClass, has_dependency, requires
4040

4141
if has_dependency("pandas"):
4242
import pandas as pd
@@ -615,6 +615,9 @@ class Test_MAPDL_commands(TestClass):
615615
"vwrite",
616616
]
617617

618+
RAISE_WARNINGS = ["eshape"]
619+
RAISE_EXCEPTIONS = []
620+
618621
@staticmethod
619622
def fake_wrap(*args, **kwags):
620623
return args[0]
@@ -658,11 +661,19 @@ def test_command(self, mapdl, cmd):
658661

659662
args = [f"arg{i}" for i in range(len(parm) - 1)] # 3 = self, cmd, kwargs
660663

661-
if list(parm)[0].lower() == "self":
662-
args = args[:-1]
663-
post = func(mapdl, *args)
664+
if cmd in self.RAISE_WARNINGS:
665+
context = pytest.warns(UserWarning)
666+
elif cmd in self.RAISE_EXCEPTIONS:
667+
context = pytest.raises(Exception)
664668
else:
665-
post = func(*args)
669+
context = NullContext()
670+
671+
with context:
672+
if list(parm)[0].lower() == "self":
673+
args = args[:-1]
674+
post = func(mapdl, *args)
675+
else:
676+
post = func(*args)
666677

667678
for arg in args:
668679
assert arg in post

tests/test_component.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def test_parsing_too_many_components(mapdl, cleared):
100100
assert "***" not in s
101101
assert "*****MAPDL" not in s
102102
for i in range(1, 100):
103-
assert re.search(f"NODE_{i:03.0f}\s+: NODE", s)
103+
assert re.search(f"NODE_{i:03.0f}" + r"\s+: NODE", s)
104104

105105

106106
class Test_components(TestClass):

tests/test_dpf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
from conftest import HAS_DPF, ON_CI, has_dependency, requires
2929

30-
if not has_dependency("ansys-dpf-core") or not HAS_DPF:
30+
if not HAS_DPF or not has_dependency("ansys-dpf-core"):
3131
pytest.skip(allow_module_level=True)
3232

3333
from ansys.dpf import core as dpf

0 commit comments

Comments
 (0)