ansys / pymapdl

Pythonic interface to MAPDL
https://mapdl.docs.pyansys.com
MIT License
424 stars 120 forks source link

feat: refactoring `create_temp_dir` #3239

Closed germa89 closed 2 months ago

germa89 commented 3 months ago

Description

Refactoring create_temp_dir and apply to MapdlPool library

Issue linked

Checklist

ansys-reviewer-bot[bot] commented 3 months ago

Thanks for opening a Pull Request. If you want to perform a review write a comment saying:

@ansys-reviewer-bot review

codecov[bot] commented 3 months ago

Codecov Report

Attention: Patch coverage is 16.66667% with 10 lines in your changes missing coverage. Please review.

Project coverage is 87.12%. Comparing base (6de31cc) to head (a7e8f8f).

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #3239 +/- ## ======================================= Coverage 87.12% 87.12% ======================================= Files 55 55 Lines 9768 9768 ======================================= Hits 8510 8510 Misses 1258 1258 ```
germa89 commented 2 months ago

Using NamedTemporaryFile breaks CICD.

germa89 commented 2 months ago

Avoiding use of __del__: https://github.com/pytest-dev/pytest-cov/issues/603

germa89 commented 2 months ago

@Gryfenfer97 for some reason tempfile.NamedTemporaryFile is breaking CICD:

tests/test_commands.py::test_output_listing[prnsol-args0] ERROR          [  1%]
tests/test_commands.py::test_output_listing[presol-args1] RERUN          [  1%]
tests/test_commands.py::test_output_listing[presol-args1] RERUN          [  1%]
tests/test_commands.py::test_output_listing[presol-args1] RERUN          [  1%]
tests/test_commands.py::test_output_listing[presol-args1] ERROR          [  1%]/opt/hostedtoolcache/Python/3.10.14/x64/lib/python3.10/site-packages/_pytest/main.py:339: PluggyTeardownRaisedWarning: A plugin raised an exception during an old-style hookwrapper teardown.
Plugin: _cov, Hook: pytest_runtestloop
DataError: Couldn't use data file '/home/runner/work/pymapdl/pymapdl/.coverage.fv-az1016-19.6296.XIDBhnCx': unable to open database file
For more information see https://pluggy.readthedocs.io/en/stable/api_reference.html#pluggy.PluggyTeardownRaisedWarning
  config.hook.pytest_runtestloop(session=session)

INTERNALERROR> Traceback (most recent call last):
INTERNALERROR>   File "/opt/hostedtoolcache/Python/3.10.14/x64/lib/python3.10/site-packages/coverage/sqlitedb.py", line 52, in _connect
INTERNALERROR>     self.con = sqlite3.connect(self.filename, check_same_thread=False)
INTERNALERROR> sqlite3.OperationalError: unable to open database file
INTERNALERROR> 
INTERNALERROR> The above exception was the direct cause of the following exception:
INTERNALERROR> 
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR>   File "/opt/hostedtoolcache/Python/3.10.14/x64/lib/python3.10/site-packages/_pytest/main.py", line 285, in wrap_session
INTERNALERROR>     session.exitstatus = doit(config, session) or 0
INTERNALERROR>   File "/opt/hostedtoolcache/Python/3.10.14/x64/lib/python3.10/site-packages/_pytest/main.py", line 339, in _main
INTERNALERROR>     config.hook.pytest_runtestloop(session=session)
INTERNALERROR>   File "/opt/hostedtoolcache/Python/3.10.14/x64/lib/python3.10/site-packages/pluggy/_hooks.py", line 513, in __call__
INTERNALERROR>     return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult)
INTERNALERROR>   File "/opt/hostedtoolcache/Python/3.10.14/x64/lib/python3.10/site-packages/pluggy/_manager.py", line 120, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
INTERNALERROR>   File "/opt/hostedtoolcache/Python/3.10.14/x64/lib/python3.10/site-packages/pluggy/_callers.py", line 156, in _multicall
INTERNALERROR>     teardown[0].send(outcome)
INTERNALERROR>   File "/opt/hostedtoolcache/Python/3.10.14/x64/lib/python3.10/site-packages/pytest_cov/plugin.py", line 339, in pytest_runtestloop
INTERNALERROR>     self.cov_controller.finish()
INTERNALERROR>   File "/opt/hostedtoolcache/Python/3.10.14/x64/lib/python3.10/site-packages/pytest_cov/engine.py", line 46, in ensure_topdir_wrapper
INTERNALERROR>     return meth(self, *args, **kwargs)
INTERNALERROR>   File "/opt/hostedtoolcache/Python/3.10.14/x64/lib/python3.10/site-packages/pytest_cov/engine.py", line 256, in finish
INTERNALERROR>     self.cov.save()
INTERNALERROR>   File "/opt/hostedtoolcache/Python/3.10.14/x64/lib/python3.10/site-packages/coverage/control.py", line 785, in save
INTERNALERROR>     data = self.get_data()
INTERNALERROR>   File "/opt/hostedtoolcache/Python/3.10.14/x64/lib/python3.10/site-packages/coverage/control.py", line 865, in get_data
INTERNALERROR>     if self._collector.flush_data():
INTERNALERROR>   File "/opt/hostedtoolcache/Python/3.10.14/x64/lib/python3.10/site-packages/coverage/collector.py", line 551, in flush_data
INTERNALERROR>     self.covdata.add_lines(self.mapped_file_dict(line_data))
INTERNALERROR>   File "/opt/hostedtoolcache/Python/3.10.14/x64/lib/python3.10/site-packages/coverage/sqldata.py", line 123, in _wrapped
INTERNALERROR>     return method(self, *args, **kwargs)
INTERNALERROR>   File "/opt/hostedtoolcache/Python/3.10.14/x64/lib/python3.10/site-packages/coverage/sqldata.py", line 494, in add_lines
INTERNALERROR>     self._choose_lines_or_arcs(lines=True)
INTERNALERROR>   File "/opt/hostedtoolcache/Python/3.10.14/x64/lib/python3.10/site-packages/coverage/sqldata.py", line 563, in _choose_lines_or_arcs
INTERNALERROR>     with self._connect() as con:
INTERNALERROR>   File "/opt/hostedtoolcache/Python/3.10.14/x64/lib/python3.10/site-packages/coverage/sqldata.py", line 343, in _connect
INTERNALERROR>     self._open_db()
INTERNALERROR>   File "/opt/hostedtoolcache/Python/3.10.14/x64/lib/python3.10/site-packages/coverage/sqldata.py", line 286, in _open_db
INTERNALERROR>     self._read_db()
INTERNALERROR>   File "/opt/hostedtoolcache/Python/3.10.14/x64/lib/python3.10/site-packages/coverage/sqldata.py", line 290, in _read_db
INTERNALERROR>     with self._dbs[threading.get_ident()] as db:
INTERNALERROR>   File "/opt/hostedtoolcache/Python/3.10.14/x64/lib/python3.10/site-packages/coverage/sqlitedb.py", line 88, in __enter__
INTERNALERROR>     self._connect()
INTERNALERROR>   File "/opt/hostedtoolcache/Python/3.10.14/x64/lib/python3.10/site-packages/coverage/sqlitedb.py", line 54, in _connect
INTERNALERROR>     raise DataError(f"Couldn't use data file {self.filename!r}: {exc}") from exc
INTERNALERROR> coverage.exceptions.DataError: Couldn't use data file '/home/runner/work/pymapdl/pymapdl/.coverage.fv-az1016-19.6296.XIDBhnCx': unable to open database file

!!!!!!!!!!!!!!!!!!!!!!!!!! stopping after 3 failures !!!!!!!!!!!!!!!!!!!!!!!!!!!
=== 1 failed, 23 passed, 5 skipped, 2 errors, 9 rerun in 1173.03s (0:19:33) ====

Reference: https://github.com/nedbat/coveragepy/issues/1303#issuecomment-2233159893