-
Notifications
You must be signed in to change notification settings - Fork 123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: adding PYMAPDL_APDL_LOG
env var for testing
#3328
Conversation
…gument. Adding also function to capture PYMAPDL_LOG_APDL env var
Thanks for opening a Pull Request. If you want to perform a review write a comment saying: @ansys-reviewer-bot review |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3328 +/- ##
==========================================
- Coverage 87.17% 87.14% -0.04%
==========================================
Files 55 55
Lines 9773 9776 +3
==========================================
- Hits 8520 8519 -1
- Misses 1253 1257 +4 |
If we use: PYMAPDL_APDL_LOG="true"$ export PYMAPDL_APDL_LOG="true"
$ pytest -k TestFieldComponentValueGetter
============================================================ test session starts ============================================================
platform darwin -- Python 3.10.13, pytest-8.2.2, pluggy-1.5.0 -- /Users/user/pymapdl/.venv/bin/python3.10
--------------------------------------------------------------Testing variables--------------------------------------------------------------
Session dependent: ON_CI (False), TESTING_MINIMAL (False), SUPPORT_PLOTTING (True)
OS dependent: ON_LINUX (False), ON_UBUNTU (False), ON_WINDOWS (False), ON_MACOS (True)
MAPDL dependent: ON_LOCAL (False), ON_STUDENT (False), HAS_GRPC (True), HAS_DPF (True), IS_SMP (True)
------------------------------------------------------------Environment variables------------------------------------------------------------
PYMAPDL_START_INSTANCE ('False'), PYMAPDL_PORT ('50052'), PYMAPDL_DB_PORT ('50095'), DPF_PORT ('50056'), DPF_START_SERVER ('false'),
-------------------------------------------------------------Pytest configuration------------------------------------------------------------
cachedir: .pytest_cache
rootdir: /Users/german.ayuso/pymapdl
configfile: pyproject.toml
testpaths: tests
plugins: cov-5.0.0, anyio-4.3.0, rerunfailures-14.0, pytest_pyvista-0.1.9, sphinx-0.6.3, memprof-0.2.0
collected 1745 items / 1741 deselected / 4 selected
tests/test_inline_functions/test_field_component_queries.py::TestFieldComponentValueGetter::test_temp PASSED [ 25%]
tests/test_inline_functions/test_field_component_queries.py::TestFieldComponentValueGetter::test_pressure FAILED [ 50%]
tests/test_inline_functions/test_field_component_queries.py::TestFieldComponentValueGetter::test_volt PASSED [ 75%]
tests/test_inline_functions/test_field_component_queries.py::TestFieldComponentValueGetter::test_mag PASSED [100%]
================================================================= FAILURES ==================================================================
________________________________________________ TestFieldComponentValueGetter.test_pressure ________________________________________________
self = <test_field_component_queries.TestFieldComponentValueGetter object at 0x1730c6230>
box_with_fields = <ansys.mapdl.core.mapdl_grpc.MapdlGrpc object at 0x1730c4520>
def test_pressure(self, box_with_fields):
mapdl = box_with_fields
mapdl.type(2)
mapdl.vmesh(1)
mapdl.d("all", "pres", 5.0)
mapdl.d("all", "ux", 0.0, lab2="uy", lab3="uz")
mapdl.slashsolu()
> mapdl.solve()
tests/test_inline_functions/test_field_component_queries.py:42:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
src/ansys/mapdl/core/_commands/solution/analysis_options.py:3477: in solve
return self.run(command, **kwargs)
src/ansys/mapdl/core/mapdl_core.py:2242: in run
self._raise_errors(text)
src/ansys/mapdl/core/mapdl_core.py:2757: in _raise_errors
self._raise_output_errors(text)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <ansys.mapdl.core.mapdl_grpc.MapdlGrpc object at 0x1730c4520>
response = '***** MAPDL SOLVE COMMAND *****\n\n *** NOTE *** CP = 145.177 TIME= 17:06:29\n ...esav\n 0.062 MB WRITTEN ON ASSEMBLED MATRIX FILE: file.full\n 0.312 MB WRITTEN ON RESULTS FILE: file.rst'
def _raise_output_errors(self, response):
"""Raise errors in the MAPDL response.
Parameters
----------
response : str
Response from MAPDL.
Raises
------
MapdlRuntimeError
For most of the errors.
"""
# The logic is to iterate for each line. If the error header is found,
# we analyse the following 'lines_number' in other to get the full error method.
# Then with regex, we collect the error message, and raise it.
for index, each_line in enumerate(response.splitlines()):
if "*** ERROR ***" in each_line:
error_is_fine = False
# Extracting only the first 'lines_number' lines.
# This is important. Regex has problems parsing long messages.
lines_number = 20
if len(response.splitlines()) <= lines_number:
partial_output = response
else:
partial_output = "\n".join(
response.splitlines()[index : (index + lines_number)]
)
# Find the error message.
# Either ends with the beginning of another error message or with double empty line.
error_message = re.search(
r"(\*\*\* ERROR \*\*\*.*?).*(?=\*\*\*|.*\n\n)", # we might consider to use only one \n.
partial_output,
re.DOTALL,
)
if not error_message:
# Since we couldn't find an error message, the full partial message (10 lines) is analysed
self._log.debug(
f"PyMAPDL could not identify the error message, the full partial message ({lines_number} lines) is analysed"
)
error_message = partial_output
else:
# Catching only the first error.
error_message = error_message.group(0)
# Trimming empty lines
error_message = "\n".join(
[each for each in error_message.splitlines() if each]
)
# Trimming empty lines
error_message = "\n".join(
[each for each in error_message.splitlines() if each]
)
# Checking for permitted error.
for each_error in _PERMITTED_ERRORS:
permited_error_message = re.search(each_error, error_message)
if permited_error_message:
error_is_fine = True
break
# Raising errors
if error_is_fine:
self._log.warn("PERMITTED ERROR: " + permited_error_message.string)
continue
else:
# We don't need to log exception because they already included in the main logger.
# logger.error(response)
# However, exceptions are recorded in the global logger which do not record
# information of the instances name, hence we edit the error message.
> raise MapdlRuntimeError(
f"\n\nError in instance {self.name}\n\n" + error_message
)
E ansys.mapdl.core.errors.MapdlRuntimeError:
E
E Error in instance GRPC_127.0.0.1:50052
E
E *** ERROR *** CP = 145.177 TIME= 17:06:29
E Element type 215 requires the definition of TB,PM with the activation
E of pressure DOF (KEYOPT(12)).
E *** NOTE *** CP = 145.177 TIME= 17:06:29
E Present time 0 is less than or equal to the previous time. Time will
E default to 1.
E *** NOTE *** CP = 145.177 TIME= 17:06:29
E This nonlinear analysis defaults to using the full Newton-Raphson
E solution procedure. This can be modified using the NROPT command.
E *** WARNING *** CP = 145.177 TIME= 17:06:29
E The program chosen initial timestep/load-factor is arbitrary. It is
E necessary for the user to supply a suitable initial
E timestep/load-factor through the NSUB or DELTIM command for
E convergence and overall efficiency.
src/ansys/mapdl/core/mapdl_core.py:2834: MapdlRuntimeError
======================================================= memory consumption estimates ========================================================
pymapdl::tests::test_inline_functions::test_field_component_queries.py::TestFieldComponentValueGetter::test_mag - 26.3 MB
pymapdl::tests::test_inline_functions::test_field_component_queries.py::TestFieldComponentValueGetter::test_pressure - 800.0 KB
pymapdl::tests::test_inline_functions::test_field_component_queries.py::TestFieldComponentValueGetter::test_temp - 400.0 KB
======================================================= PyMAPDL Pytest short summary ========================================================
[FAILED] TestFieldComponentValueGetter.test_pressure - E convergence and overall efficiency.
=============================================== 1 failed, 3 passed, 1741 deselected in 3.09s ================================================ and a file
PYMAPDL_APDL_LOG="myapdl.log"We can specify another file name: $ export PYMAPDL_APDL_LOG="myapdl.log"
$ pytest -k TestFieldComponentValueGetter which will generate a file named |
@pyansys-ci-bot LGTM. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Description
apdl_log
argument when testing.Issue linked
NA
Checklist
draft
if it is not ready to be reviewed yet.feat: adding new MAPDL command
)