From 849219d45ad9d7cec8648725ebd487598ad7c798 Mon Sep 17 00:00:00 2001 From: mvdbeek Date: Fri, 28 Jul 2023 17:23:06 +0200 Subject: [PATCH 1/4] Skip postgres unit tests from psycopg2 not installed --- test/unit/app/queue_worker/conftest.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/test/unit/app/queue_worker/conftest.py b/test/unit/app/queue_worker/conftest.py index a3683b2f1ac0..b117847b40cb 100644 --- a/test/unit/app/queue_worker/conftest.py +++ b/test/unit/app/queue_worker/conftest.py @@ -48,6 +48,9 @@ def create_app(): def postgres_app(postgresql_proc): connection = "postgresql://{p.user}@{p.host}:{p.port}/".format(p=postgresql_proc) + if not psycopg2: + pytest.skip("psycopg2 must be installed for postgresql fixture") + def create_app(): return create_base_test(connection, amqp_type="postgres") @@ -59,9 +62,10 @@ def database_app(request): if request.param == "postgres_app": if not which("initdb"): pytest.skip("initdb must be on PATH for postgresql fixture") - if not psycopg2: - pytest.skip("psycopg2 must be installed for postgresql fixture") if request.param == "sqlite_rabbitmq_app": if not os.environ.get("GALAXY_TEST_AMQP_INTERNAL_CONNECTION"): pytest.skip("rabbitmq tests will be skipped if GALAXY_TEST_AMQP_INTERNAL_CONNECTION env var is unset") - return request.getfixturevalue(request.param) + try: + return request.getfixturevalue(request.param) + except ImportError: + pytest.skip("psycopg2 must be installed for postgresql fixture") From b61fa18616fbecae20bd0a5d74a08c6d5ffa3dcd Mon Sep 17 00:00:00 2001 From: mvdbeek Date: Fri, 28 Jul 2023 17:36:10 +0200 Subject: [PATCH 2/4] Fix ``test_most_recently_used`` I see this failing about 50% of the time, and if it fails history1 and history2 have the same update time. --- test/unit/app/managers/test_HistoryManager.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/unit/app/managers/test_HistoryManager.py b/test/unit/app/managers/test_HistoryManager.py index 3944a1184715..32be275d4db1 100644 --- a/test/unit/app/managers/test_HistoryManager.py +++ b/test/unit/app/managers/test_HistoryManager.py @@ -1,3 +1,4 @@ +import time from unittest import mock import pytest @@ -337,6 +338,9 @@ def test_most_recently_used(self): history1 = self.history_manager.create(name="history1", user=user2) self.trans.set_history(history1) + + # sleep a tiny bit so update time for history2 is different from history1 + time.sleep(0.1) history2 = self.history_manager.create(name="history2", user=user2) self.log("should be able to get the most recently used (updated) history for a given user") From d543702e4ba4028513327537ad2b7bbc76f8ce5d Mon Sep 17 00:00:00 2001 From: Nicola Soranzo Date: Sat, 29 Jul 2023 00:27:57 +0100 Subject: [PATCH 3/4] pytest-postgresql requires psycopg See https://github.com/ClearcodeHQ/pytest-postgresql#how-to-use Fix failing queue_worker unit tests when psycopg2 is installed (otherwise they are skipped): ``` $ pytest test/unit/app/queue_worker/test_database_heartbeat.py::test_database_heartbeat[postgres_app] ... _________________________________________________________________________ ERROR at setup of test_database_heartbeat[postgres_app] _________________________________________________________________________ request = > @pytest.fixture(params=["postgres_app", "sqlite_app", "sqlite_rabbitmq_app"]) def database_app(request): if request.param == "postgres_app": if not which("initdb"): pytest.skip("initdb must be on PATH for postgresql fixture") if not psycopg2: pytest.skip("psycopg2 must be installed for postgresql fixture") if request.param == "sqlite_rabbitmq_app": if not os.environ.get("GALAXY_TEST_AMQP_INTERNAL_CONNECTION"): pytest.skip("rabbitmq tests will be skipped if GALAXY_TEST_AMQP_INTERNAL_CONNECTION env var is unset") > return request.getfixturevalue(request.param) test/unit/app/queue_worker/conftest.py:67: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ .venv/lib/python3.10/site-packages/pytest_postgresql/factories/process.py:147: in postgresql_proc_fixture with DatabaseJanitor( .venv/lib/python3.10/site-packages/pytest_postgresql/janitor.py:54: in __init__ check_for_psycopg() _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def check_for_psycopg() -> None: """ Function checks whether psycopg was imported. Raises ImportError if not. """ if not psycopg: > raise ImportError("No module named psycopg. Please install psycopg.") E ImportError: No module named psycopg. Please install psycopg. .venv/lib/python3.10/site-packages/pytest_postgresql/compat.py:35: ImportError ``` Also, remove check for `initdb` in PATH, because on Ubuntu it's installed in `/usr/lib/postgresql/VERSION/bin/initdb` . --- test/unit/app/queue_worker/conftest.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/test/unit/app/queue_worker/conftest.py b/test/unit/app/queue_worker/conftest.py index b117847b40cb..3849e7b86904 100644 --- a/test/unit/app/queue_worker/conftest.py +++ b/test/unit/app/queue_worker/conftest.py @@ -4,13 +4,17 @@ import pytest +try: + import psycopg +except ImportError: + psycopg = None + try: import psycopg2 except ImportError: psycopg2 = None from galaxy.app_unittest_utils import galaxy_mock -from galaxy.util import which def create_base_test(connection, amqp_type: str, amqp_connection: Optional[str] = None): @@ -48,9 +52,6 @@ def create_app(): def postgres_app(postgresql_proc): connection = "postgresql://{p.user}@{p.host}:{p.port}/".format(p=postgresql_proc) - if not psycopg2: - pytest.skip("psycopg2 must be installed for postgresql fixture") - def create_app(): return create_base_test(connection, amqp_type="postgres") @@ -60,12 +61,11 @@ def create_app(): @pytest.fixture(params=["postgres_app", "sqlite_app", "sqlite_rabbitmq_app"]) def database_app(request): if request.param == "postgres_app": - if not which("initdb"): - pytest.skip("initdb must be on PATH for postgresql fixture") + if not psycopg: + pytest.skip("psycopg must be installed for postgresql_proc fixture") + if not psycopg2: + pytest.skip("psycopg2 must be installed for database_app fixture") if request.param == "sqlite_rabbitmq_app": if not os.environ.get("GALAXY_TEST_AMQP_INTERNAL_CONNECTION"): pytest.skip("rabbitmq tests will be skipped if GALAXY_TEST_AMQP_INTERNAL_CONNECTION env var is unset") - try: - return request.getfixturevalue(request.param) - except ImportError: - pytest.skip("psycopg2 must be installed for postgresql fixture") + return request.getfixturevalue(request.param) From e25e27b6bc84d6f7bd194252ba931fb8e8790a8d Mon Sep 17 00:00:00 2001 From: Nicola Soranzo Date: Sat, 29 Jul 2023 00:54:17 +0100 Subject: [PATCH 4/4] Fix merge forward of commit 77c0e915b0de6c45e638f515cae86aeac6fea965 --- test/unit/tool_util/test_tool_linters.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/tool_util/test_tool_linters.py b/test/unit/tool_util/test_tool_linters.py index f0e28eebe859..60ff02c52cf2 100644 --- a/test/unit/tool_util/test_tool_linters.py +++ b/test/unit/tool_util/test_tool_linters.py @@ -1046,7 +1046,7 @@ def test_general_valid(lint_ctx): def test_general_valid_new_profile_fmt(lint_ctx): tool_source = get_xml_tool_source(GENERAL_VALID_NEW_PROFILE_FMT) - run_lint(lint_ctx, general.lint_general, XmlToolSource(tool_source)) + run_lint(lint_ctx, general.lint_general, tool_source) assert "Tool defines a version [1.0+galaxy1]." in lint_ctx.valid_messages assert "Tool specifies profile version [23.0]." in lint_ctx.valid_messages assert "Tool defines an id [valid_id]." in lint_ctx.valid_messages