From 50af64263e0a84cf4a5fc36da5c545024674c7a2 Mon Sep 17 00:00:00 2001 From: mvdbeek Date: Fri, 29 Dec 2023 11:41:51 +0200 Subject: [PATCH 1/8] Use single test instance for API tests --- lib/galaxy_test/api/conftest.py | 24 ++++++++++++++++++++++++ lib/galaxy_test/base/testcase.py | 13 +++++-------- 2 files changed, 29 insertions(+), 8 deletions(-) create mode 100644 lib/galaxy_test/api/conftest.py diff --git a/lib/galaxy_test/api/conftest.py b/lib/galaxy_test/api/conftest.py new file mode 100644 index 000000000000..feee35a5512a --- /dev/null +++ b/lib/galaxy_test/api/conftest.py @@ -0,0 +1,24 @@ +import os + +import pytest + +from galaxy_test.api._framework import ApiTestCase +from galaxy_test.driver.driver_util import GalaxyTestDriver + + +@pytest.fixture(scope="session") +def real_driver(): + if not os.environ.get("GALAXY_TEST_ENVIRONMENT_CONFIGURED"): + driver = GalaxyTestDriver() + driver.setup(ApiTestCase) + try: + yield driver + finally: + driver.tear_down() + else: + yield None + + +@pytest.fixture(scope="class") +def embedded_driver(real_driver, request): + request.cls._test_driver = real_driver diff --git a/lib/galaxy_test/base/testcase.py b/lib/galaxy_test/base/testcase.py index 4b14e6da2bfd..6f148d19840b 100644 --- a/lib/galaxy_test/base/testcase.py +++ b/lib/galaxy_test/base/testcase.py @@ -1,10 +1,11 @@ import logging -import os from typing import ( Any, Optional, ) +import pytest + from galaxy.tool_util.verify.test_data import TestDataResolver from galaxy.util.unittest import TestCase from galaxy_test.base.env import ( @@ -15,6 +16,7 @@ log = logging.getLogger(__name__) +@pytest.mark.usefixtures("embedded_driver") class FunctionalTestCase(TestCase): """Base class for tests targetting actual Galaxy servers. @@ -46,17 +48,12 @@ def setUp(self) -> None: @classmethod def setUpClass(cls): """Configure and start Galaxy for a test.""" - cls._test_driver = None - - if cls.galaxy_driver_class is not None and not os.environ.get("GALAXY_TEST_ENVIRONMENT_CONFIGURED"): - cls._test_driver = cls.galaxy_driver_class() - cls._test_driver.setup(config_object=cls) + pass @classmethod def tearDownClass(cls): """Shutdown Galaxy server and cleanup temp directory.""" - if cls._test_driver: - cls._test_driver.tear_down() + pass def get_filename(self, filename: str) -> str: # No longer used by tool tests - drop if isn't used else where. From da794aa6c858e59e37f66215712aac785334a5b4 Mon Sep 17 00:00:00 2001 From: mvdbeek Date: Fri, 29 Dec 2023 11:35:38 +0200 Subject: [PATCH 2/8] Fix item tags API tests to use ApiTestCase --- lib/galaxy_test/api/test_item_tags.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/galaxy_test/api/test_item_tags.py b/lib/galaxy_test/api/test_item_tags.py index 3bf856126c8d..3b9527f7b37f 100644 --- a/lib/galaxy_test/api/test_item_tags.py +++ b/lib/galaxy_test/api/test_item_tags.py @@ -8,10 +8,10 @@ DatasetPopulator, WorkflowPopulator, ) -from galaxy_test.driver import integration_util +from ._framework import ApiTestCase -class TestItemTagsApi(integration_util.IntegrationTestCase): +class TestItemTagsApi(ApiTestCase): dataset_populator: DatasetPopulator @classmethod From c87c5194981cdbedffb9bc92127ebda62be90012 Mon Sep 17 00:00:00 2001 From: mvdbeek Date: Fri, 29 Dec 2023 11:57:25 +0200 Subject: [PATCH 3/8] Move fixture one level higher --- lib/galaxy_test/api/conftest.py | 24 ------------------------ lib/galaxy_test/conftest.py | 20 ++++++++++++++++++++ 2 files changed, 20 insertions(+), 24 deletions(-) delete mode 100644 lib/galaxy_test/api/conftest.py diff --git a/lib/galaxy_test/api/conftest.py b/lib/galaxy_test/api/conftest.py deleted file mode 100644 index feee35a5512a..000000000000 --- a/lib/galaxy_test/api/conftest.py +++ /dev/null @@ -1,24 +0,0 @@ -import os - -import pytest - -from galaxy_test.api._framework import ApiTestCase -from galaxy_test.driver.driver_util import GalaxyTestDriver - - -@pytest.fixture(scope="session") -def real_driver(): - if not os.environ.get("GALAXY_TEST_ENVIRONMENT_CONFIGURED"): - driver = GalaxyTestDriver() - driver.setup(ApiTestCase) - try: - yield driver - finally: - driver.tear_down() - else: - yield None - - -@pytest.fixture(scope="class") -def embedded_driver(real_driver, request): - request.cls._test_driver = real_driver diff --git a/lib/galaxy_test/conftest.py b/lib/galaxy_test/conftest.py index 1e7e3b45106f..64f69aee6f57 100644 --- a/lib/galaxy_test/conftest.py +++ b/lib/galaxy_test/conftest.py @@ -8,6 +8,8 @@ from galaxy.util import DEFAULT_SOCKET_TIMEOUT from galaxy.web import statsd_client as statsd +from galaxy_test.api._framework import ApiTestCase +from galaxy_test.driver.driver_util import GalaxyTestDriver @pytest.fixture(scope="session", autouse=True) @@ -15,6 +17,24 @@ def celery_includes(): yield ["galaxy.celery.tasks"] +@pytest.fixture(scope="session") +def real_driver(): + if not os.environ.get("GALAXY_TEST_ENVIRONMENT_CONFIGURED"): + driver = GalaxyTestDriver() + driver.setup(ApiTestCase) + try: + yield driver + finally: + driver.tear_down() + else: + yield None + + +@pytest.fixture(scope="class") +def embedded_driver(real_driver, request): + request.cls._test_driver = real_driver + + def get_timings(test_uuid): # timestamps didn't work - telegraf didn't sample at small enough granularity # fs = datetime.datetime.fromtimestamp(from_timestamp).strftime('%Y-%m-%dT%H:%M:%S.%fZ') From c174b38955c07a25af31df9f8e3b0078349613ac Mon Sep 17 00:00:00 2001 From: mvdbeek Date: Fri, 29 Dec 2023 12:59:48 +0200 Subject: [PATCH 4/8] Import galaxy driver in tool shed tests --- lib/tool_shed/test/conftest.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/tool_shed/test/conftest.py b/lib/tool_shed/test/conftest.py index 5e1f347318f2..753612c314fd 100644 --- a/lib/tool_shed/test/conftest.py +++ b/lib/tool_shed/test/conftest.py @@ -2,6 +2,10 @@ import pytest +from galaxy_test.conftest import ( # noqa: F401 + embedded_driver, + real_driver, +) from tool_shed.test.base import driver From f1e32778f4dc4b7144a8ef93b76044e3540c2431 Mon Sep 17 00:00:00 2001 From: mvdbeek Date: Sat, 30 Dec 2023 13:16:59 +0200 Subject: [PATCH 5/8] Fix url scheme assertion message --- lib/galaxy/util/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/galaxy/util/__init__.py b/lib/galaxy/util/__init__.py index af5c405d3609..d3223fc7c0fa 100644 --- a/lib/galaxy/util/__init__.py +++ b/lib/galaxy/util/__init__.py @@ -1734,7 +1734,7 @@ def build_url(base_url, port=80, scheme="http", pathspec=None, params=None, dose parsed_url = urlparse(base_url) if scheme != "http": parsed_url.scheme = scheme - assert parsed_url.scheme in ("http", "https", "ftp"), f"Invalid URL scheme: {scheme}" + assert parsed_url.scheme in ("http", "https", "ftp"), f"Invalid URL scheme: {parsed_url.scheme}" if port != 80: url = "%s://%s:%d/%s" % (parsed_url.scheme, parsed_url.netloc.rstrip("/"), int(port), parsed_url.path) else: From d65d3112ac0039336e2bd5ee7101df79383110d9 Mon Sep 17 00:00:00 2001 From: mvdbeek Date: Sat, 30 Dec 2023 13:41:08 +0200 Subject: [PATCH 6/8] Make framework tool tests use driver fixture --- test/functional/conftest.py | 38 ++++++++++++++++++++------ test/functional/test_toolbox_pytest.py | 11 +++----- 2 files changed, 33 insertions(+), 16 deletions(-) diff --git a/test/functional/conftest.py b/test/functional/conftest.py index 76c1603839ed..85dcb4532649 100644 --- a/test/functional/conftest.py +++ b/test/functional/conftest.py @@ -1,9 +1,29 @@ -def pytest_unconfigure(config): - try: - # This needs to be run if no test were run. - from .test_toolbox_pytest import DRIVER - - DRIVER.tear_down() - print("Galaxy test driver shutdown successful") - except Exception: - pass +import os + +import pytest + +from galaxy_test.driver.driver_util import GalaxyTestDriver +from .test_toolbox_pytest import TestFrameworkTools + + +@pytest.fixture(scope="session", autouse=True) +def celery_includes(): + yield ["galaxy.celery.tasks"] + + +@pytest.fixture(scope="session") +def real_driver(): + if not os.environ.get("GALAXY_TEST_ENVIRONMENT_CONFIGURED"): + driver = GalaxyTestDriver() + driver.setup(TestFrameworkTools) + try: + yield driver + finally: + driver.tear_down() + else: + yield None + + +@pytest.fixture(scope="class") +def embedded_driver(real_driver, request): + request.cls._test_driver = real_driver diff --git a/test/functional/test_toolbox_pytest.py b/test/functional/test_toolbox_pytest.py index 6bb11e919c02..896e3609913e 100644 --- a/test/functional/test_toolbox_pytest.py +++ b/test/functional/test_toolbox_pytest.py @@ -1,16 +1,13 @@ import os -import sys from typing import ( List, NamedTuple, ) -galaxy_root = os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir + "/" + os.path.pardir)) -sys.path[1:1] = [os.path.join(galaxy_root, "lib"), os.path.join(galaxy_root, "test")] - import pytest from galaxy_test.api._framework import ApiTestCase +from galaxy_test.driver.driver_util import GalaxyTestDriver SKIPTEST = os.path.join(os.path.dirname(__file__), "known_broken_tools.txt") @@ -29,7 +26,8 @@ def get_skiplist(): def get_cases() -> List[ToolTest]: atc = ApiTestCase() - atc.setUpClass() + atc._test_driver = GalaxyTestDriver() + atc._test_driver.setup() atc.setUp() test_summary = atc.galaxy_interactor.get_tests_summary() test_cases = [] @@ -37,8 +35,7 @@ def get_cases() -> List[ToolTest]: for tool_version, tool_dict in summary_dict.items(): for index in range(tool_dict["count"]): test_cases.append(ToolTest(tool_id, tool_version, index)) - atc.tearDown() - atc.tearDownClass() + atc._test_driver.stop_servers() return test_cases From 50d81b888555a512fb7b7cd05e6357998423b109 Mon Sep 17 00:00:00 2001 From: mvdbeek Date: Sat, 30 Dec 2023 13:44:29 +0200 Subject: [PATCH 7/8] Override fixture for TS tests --- lib/tool_shed/test/base/api.py | 4 ++-- lib/tool_shed/test/conftest.py | 6 +----- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/lib/tool_shed/test/base/api.py b/lib/tool_shed/test/base/api.py index 0983dd88d3e6..fc2d93f9a0cc 100644 --- a/lib/tool_shed/test/base/api.py +++ b/lib/tool_shed/test/base/api.py @@ -90,8 +90,8 @@ def tearDownClass(cls): pass @pytest.fixture(autouse=True) - def _get_driver(self, tool_shed_test_driver): - self._test_driver = tool_shed_test_driver + def _get_driver(self, embedded_driver): + self._test_driver = embedded_driver class ShedGalaxyInteractorApi(GalaxyInteractorApi): diff --git a/lib/tool_shed/test/conftest.py b/lib/tool_shed/test/conftest.py index 753612c314fd..c754f99ebb1b 100644 --- a/lib/tool_shed/test/conftest.py +++ b/lib/tool_shed/test/conftest.py @@ -2,15 +2,11 @@ import pytest -from galaxy_test.conftest import ( # noqa: F401 - embedded_driver, - real_driver, -) from tool_shed.test.base import driver @pytest.fixture(scope="session") -def tool_shed_test_driver(): +def embedded_driver(): if not os.environ.get("GALAXY_TEST_ENVIRONMENT_CONFIGURED"): ts_driver = driver.ToolShedTestDriver() ts_driver.setup() From 1b7a74aaca1d0c9d22c8d55e001c56fd837a725b Mon Sep 17 00:00:00 2001 From: mvdbeek Date: Mon, 1 Jan 2024 19:03:37 +0200 Subject: [PATCH 8/8] Override test class in selenium driver --- lib/galaxy_test/selenium/conftest.py | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) mode change 120000 => 100644 lib/galaxy_test/selenium/conftest.py diff --git a/lib/galaxy_test/selenium/conftest.py b/lib/galaxy_test/selenium/conftest.py deleted file mode 120000 index 0290a1307861..000000000000 --- a/lib/galaxy_test/selenium/conftest.py +++ /dev/null @@ -1 +0,0 @@ -../conftest.py \ No newline at end of file diff --git a/lib/galaxy_test/selenium/conftest.py b/lib/galaxy_test/selenium/conftest.py new file mode 100644 index 000000000000..4e717b1f1a03 --- /dev/null +++ b/lib/galaxy_test/selenium/conftest.py @@ -0,0 +1,24 @@ +import os + +import pytest + +from galaxy_test.driver.driver_util import GalaxyTestDriver +from galaxy_test.selenium.framework import SeleniumTestCase + + +@pytest.fixture(scope="session") +def real_driver(): + if not os.environ.get("GALAXY_TEST_ENVIRONMENT_CONFIGURED"): + driver = GalaxyTestDriver() + driver.setup(SeleniumTestCase) + try: + yield driver + finally: + driver.tear_down() + else: + yield None + + +@pytest.fixture(scope="class") +def embedded_driver(real_driver, request): + request.cls._test_driver = real_driver