diff --git a/doc/changelog.d/3554.added.md b/doc/changelog.d/3554.added.md new file mode 100644 index 0000000000..41caad6cb3 --- /dev/null +++ b/doc/changelog.d/3554.added.md @@ -0,0 +1 @@ +test: adding test for start_timeout arg \ No newline at end of file diff --git a/tests/conftest.py b/tests/conftest.py index 98bfe2e3e9..4742b6326c 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -663,7 +663,7 @@ def _patch_method(method): return "ansys.mapdl.core.mapdl_grpc.MapdlGrpc." + method -_meth_patch_MAPDL_launch = ( +_meth_patch_MAPDL_launch = [ # method, and its return (_patch_method("_connect"), _returns(True)), (_patch_method("_run"), _returns("")), @@ -682,10 +682,24 @@ def _patch_method(method): ] ), ), +] + +_meth_patch_MAPDL = _meth_patch_MAPDL_launch.copy() +_meth_patch_MAPDL.extend( + [ + # launcher methods + ("ansys.mapdl.core.launcher.launch_grpc", _returns(None)), + ("ansys.mapdl.core.launcher.check_mapdl_launch", _returns(None)), + ] ) +# For testing +# Patch some of the starting procedures PATCH_MAPDL_START = [patch(method, ret) for method, ret in _meth_patch_MAPDL_launch] +# 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): diff --git a/tests/test_launcher.py b/tests/test_launcher.py index f530ba0a8c..4633a3f029 100644 --- a/tests/test_launcher.py +++ b/tests/test_launcher.py @@ -76,6 +76,7 @@ from ansys.mapdl.core.misc import stack from conftest import ( ON_LOCAL, + PATCH_MAPDL, PATCH_MAPDL_START, QUICK_LAUNCH_SWITCHES, TESTING_MINIMAL, @@ -263,7 +264,6 @@ def test_license_type_dummy(mapdl): ): launch_mapdl( start_instance=True, - port=mapdl.port + 1, additional_switches=f" -p {dummy_license_type} " + QUICK_LAUNCH_SWITCHES, start_timeout=start_timeout, license_server_check=False, @@ -1894,3 +1894,32 @@ def return_everything(*arg, **kwags): assert isinstance(kwargs["stderr"], type(subprocess.PIPE)) assert kwargs["env"] == envvars + + +@requires("ansys-tools-path") +@patch( + "ansys.tools.path.path._get_application_path", + lambda *args, **kwargs: "path/to/mapdl/executable", +) +@patch("ansys.tools.path.path._mapdl_version_from_path", lambda *args, **kwargs: 242) +@stack(*PATCH_MAPDL) +@pytest.mark.parametrize( + "arg,value,method", + [ + ("start_timeout", 88, "_timeout"), + ("start_timeout", 1099, "_timeout"), + ("cleanup_on_exit", False, "_cleanup"), + ("cleanup_on_exit", True, "_cleanup"), + ("jobname", "myjobnamestrange", "_jobname"), + ("jobid", 1088, "_jobid"), + ("finish_job_on_exit", True, "finish_job_on_exit"), + ("finish_job_on_exit", False, "finish_job_on_exit"), + ], +) +def test_args_pass(monkeypatch, arg, value, method): + monkeypatch.delenv("PYMAPDL_START_INSTANCE", False) + + kwargs = {arg: value} + mapdl = launch_mapdl(**kwargs) + meth = getattr(mapdl, method) + assert meth == value