diff --git a/lib/galaxy_test/base/env.py b/lib/galaxy_test/base/env.py index 0caee6da17f3..27a149b8f270 100644 --- a/lib/galaxy_test/base/env.py +++ b/lib/galaxy_test/base/env.py @@ -12,6 +12,8 @@ DEFAULT_WEB_HOST = socket.gethostbyname("localhost") +GalaxyTarget = Tuple[str, Optional[str], str] + def setup_keep_outdir() -> str: keep_outdir = os.environ.get("GALAXY_TEST_SAVE", "") @@ -23,7 +25,7 @@ def setup_keep_outdir() -> str: return keep_outdir -def target_url_parts() -> Tuple[str, Optional[str], str]: +def target_url_parts() -> GalaxyTarget: host = socket.gethostbyname(os.environ.get("GALAXY_TEST_HOST", DEFAULT_WEB_HOST)) port = os.environ.get("GALAXY_TEST_PORT") if port: diff --git a/lib/galaxy_test/base/testcase.py b/lib/galaxy_test/base/testcase.py index 6f148d19840b..58acf00ea408 100644 --- a/lib/galaxy_test/base/testcase.py +++ b/lib/galaxy_test/base/testcase.py @@ -9,6 +9,7 @@ from galaxy.tool_util.verify.test_data import TestDataResolver from galaxy.util.unittest import TestCase from galaxy_test.base.env import ( + GalaxyTarget, setup_keep_outdir, target_url_parts, ) @@ -16,6 +17,16 @@ log = logging.getLogger(__name__) +def host_port_and_url(test_driver: Optional[Any]) -> GalaxyTarget: + host, port, url = target_url_parts() + server_wrapper = test_driver and test_driver.server_wrappers and test_driver.server_wrappers[0] + if server_wrapper: + host = server_wrapper.host + port = server_wrapper.port + url = f"http://{host}:{port}{server_wrapper.prefix.rstrip('/')}/" + return host, port, url + + @pytest.mark.usefixtures("embedded_driver") class FunctionalTestCase(TestCase): """Base class for tests targetting actual Galaxy servers. @@ -34,14 +45,7 @@ class FunctionalTestCase(TestCase): _test_driver: Optional[Any] def setUp(self) -> None: - self.host, self.port, self.url = target_url_parts() - server_wrapper = ( - self._test_driver and self._test_driver.server_wrappers and self._test_driver.server_wrappers[0] - ) - if server_wrapper: - self.host = server_wrapper.host - self.port = server_wrapper.port - self.url = f"http://{self.host}:{self.port}{server_wrapper.prefix.rstrip('/')}/" + self.host, self.port, self.url = host_port_and_url(self._test_driver) self.test_data_resolver = TestDataResolver() self.keepOutdir = setup_keep_outdir()