From ccd3ea462bc7e74b89413c8acc49c59f4fe6a2f9 Mon Sep 17 00:00:00 2001 From: german Date: Wed, 20 Mar 2024 11:46:25 +0000 Subject: [PATCH] making ports depending on the mapdl fixture --- tests/test_launcher.py | 58 ++++++++++++++++++++--------------------- tests/test_licensing.py | 9 ++++--- 2 files changed, 33 insertions(+), 34 deletions(-) diff --git a/tests/test_launcher.py b/tests/test_launcher.py index 6425ff4551..a0032df216 100644 --- a/tests/test_launcher.py +++ b/tests/test_launcher.py @@ -52,8 +52,6 @@ from ansys.mapdl.core.licensing import LICENSES from conftest import ON_LOCAL, QUICK_LAUNCH_SWITCHES, NullContext, requires -PORT_TEST = 50053 - try: from ansys.tools.path import ( find_ansys, @@ -183,21 +181,21 @@ def test_launch_console(version): @requires("local") @requires("nostudent") -def test_license_type_keyword(): +def test_license_type_keyword(mapdl): checks = [] for license_name, license_description in LICENSES.items(): try: - mapdl = launch_mapdl( + mapdl_ = launch_mapdl( license_type=license_name, start_timeout=start_timeout, - port=PORT_TEST, + port=mapdl.port + 1, additional_switches=QUICK_LAUNCH_SWITCHES, ) # Using first line to ensure not picking up other stuff. - checks.append(license_description in mapdl.__str__().split("\n")[0]) - mapdl.exit() - del mapdl + checks.append(license_description in mapdl_.__str__().split("\n")[0]) + mapdl_.exit() + del mapdl_ sleep(2) except MapdlDidNotStart as e: @@ -211,45 +209,45 @@ def test_license_type_keyword(): @requires("local") @requires("nostudent") -def test_license_type_keyword_names(): +def test_license_type_keyword_names(mapdl): # This test might became a way to check available licenses, which is not the purpose. successful_check = False for license_name, license_description in LICENSES.items(): - mapdl = launch_mapdl( + mapdl_ = launch_mapdl( license_type=license_name, start_timeout=start_timeout, - port=PORT_TEST, + port=mapdl.port + 1, additional_switches=QUICK_LAUNCH_SWITCHES, ) # Using first line to ensure not picking up other stuff. successful_check = ( - license_description in mapdl.__str__().split("\n")[0] or successful_check + license_description in mapdl_.__str__().split("\n")[0] or successful_check ) - assert license_description in mapdl.__str__().split("\n")[0] - mapdl.exit() + assert license_description in mapdl_.__str__().split("\n")[0] + mapdl_.exit() assert successful_check # if at least one license is ok, this should be true. @requires("local") @requires("nostudent") -def test_license_type_additional_switch(): +def test_license_type_additional_switch(mapdl): # This test might became a way to check available licenses, which is not the purpose. successful_check = False for license_name, license_description in LICENSES.items(): - mapdl = launch_mapdl( + mapdl_ = launch_mapdl( additional_switches=QUICK_LAUNCH_SWITCHES + " -p " + license_name, start_timeout=start_timeout, - port=PORT_TEST, + port=mapdl.port + 1, ) # Using first line to ensure not picking up other stuff. successful_check = ( - license_description in mapdl.__str__().split("\n")[0] or successful_check + license_description in mapdl_.__str__().split("\n")[0] or successful_check ) - mapdl.exit() + mapdl_.exit() assert successful_check # if at least one license is ok, this should be true. @@ -260,7 +258,7 @@ def test_license_type_dummy(mapdl): dummy_license_type = "dummy" with pytest.raises(LicenseServerConnectionError): launch_mapdl( - port=PORT_TEST, + port=mapdl.port + 1, additional_switches=f" -p {dummy_license_type}" + QUICK_LAUNCH_SWITCHES, start_timeout=start_timeout, ) @@ -270,16 +268,16 @@ def test_license_type_dummy(mapdl): @requires("nostudent") def test_remove_temp_files(mapdl): """Ensure the working directory is removed when run_location is not set.""" - mapdl = launch_mapdl( - port=PORT_TEST, + mapdl_ = launch_mapdl( + port=mapdl.port + 1, remove_temp_files=True, start_timeout=start_timeout, additional_switches=QUICK_LAUNCH_SWITCHES, ) # possible MAPDL is installed but running in "remote" mode - path = mapdl.directory - mapdl.exit() + path = mapdl_.directory + mapdl_.exit() tmp_dir = tempfile.gettempdir() ans_temp_dir = os.path.join(tmp_dir, "ansys_") @@ -293,17 +291,17 @@ def test_remove_temp_files(mapdl): @requires("nostudent") def test_remove_temp_files_fail(tmpdir, mapdl): """Ensure the working directory is not removed when the cwd is changed.""" - mapdl = launch_mapdl( - port=PORT_TEST, + mapdl_ = launch_mapdl( + port=mapdl.port + 1, remove_temp_files=True, start_timeout=start_timeout, additional_switches=QUICK_LAUNCH_SWITCHES, ) - old_path = mapdl.directory + old_path = mapdl_.directory assert os.path.isdir(str(tmpdir)) - mapdl.cwd(str(tmpdir)) - path = mapdl.directory - mapdl.exit() + mapdl_.cwd(str(tmpdir)) + path = mapdl_.directory + mapdl_.exit() assert os.path.isdir(path) # Checking no changes in the old path diff --git a/tests/test_licensing.py b/tests/test_licensing.py index def8e3a383..e521d65462 100644 --- a/tests/test_licensing.py +++ b/tests/test_licensing.py @@ -182,20 +182,21 @@ def test_license_checker(tmpdir, license_checker): @requires("local") @skip_no_lic_bin -def test_check_license_file(tmpdir): +def test_check_license_file(tmpdir, mapdl): timeout = 15 checker = licensing.LicenseChecker(timeout=timeout) # start the license check in the background checker.start(checkout_license=False) try: - mapdl = launch_mapdl( + mapdl_ = launch_mapdl( license_server_check=False, start_timeout=timeout, additional_switches=QUICK_LAUNCH_SWITCHES, + port=mapdl.port + 1, ) - assert mapdl._local - mapdl.exit() + assert mapdl_._local + mapdl_.exit() except IOError: # MAPDL never started assert not checker._license_file_success else: