Skip to content

Commit

Permalink
Provide explicit reason when client/server tests are skipped
Browse files Browse the repository at this point in the history
Sometimes it's not missing Safir or httpx but a circular import.
  • Loading branch information
timj committed Aug 15, 2024
1 parent 70b33aa commit 04b15dc
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 10 deletions.
7 changes: 5 additions & 2 deletions tests/test_query_remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,16 @@

try:
from lsst.daf.butler.tests.server import create_test_server
except ImportError:

reason_text = ""
except ImportError as e:
create_test_server = None
reason_text = str(e)

TESTDIR = os.path.abspath(os.path.dirname(__file__))


@unittest.skipIf(create_test_server is None, "Server dependencies not installed.")
@unittest.skipIf(create_test_server is None, f"Server dependencies not installed: {reason_text}")
class RemoteButlerQueryTests(ButlerQueryTests, unittest.TestCase):
"""Test query system using client/server butler."""

Expand Down
26 changes: 20 additions & 6 deletions tests/test_remote_butler.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,28 @@
try:
import httpx
from lsst.daf.butler.remote_butler import ButlerServerError, RemoteButler
except ImportError:

remote_butler_import_fail_message = ""
except ImportError as e:
# httpx is not available in rubin-env yet, so skip these tests if it's not
# available
RemoteButler = None
remote_butler_import_fail_message = str(e)

try:
from lsst.daf.butler.tests.server import create_test_server
except ImportError:

server_import_fail_message = ""
except ImportError as e:
create_test_server = None
server_import_fail_message = str(e)

TESTDIR = os.path.abspath(os.path.dirname(__file__))


@unittest.skipIf(RemoteButler is None, "httpx is not installed")
@unittest.skipIf(
RemoteButler is None, f"Remote butler can not be imported: {remote_butler_import_fail_message}"
)
class RemoteButlerConfigTests(unittest.TestCase):
"""Test construction of RemoteButler via Butler()"""

Expand All @@ -64,7 +72,9 @@ def test_bad_config(self):
Butler({"cls": "lsst.daf.butler.remote_butler.RemoteButler", "remote_butler": {"url": "!"}})


@unittest.skipIf(create_test_server is None, "Server dependencies not installed")
@unittest.skipIf(
create_test_server is None, f"Server dependencies not installed: {server_import_fail_message}"
)
class RemoteButlerErrorHandlingTests(unittest.TestCase):
"""Test RemoteButler error handling."""

Expand Down Expand Up @@ -200,7 +210,9 @@ def test_query_projection_drop_postprocessing(self):
pass


@unittest.skipIf(create_test_server is None, "Server dependencies not installed.")
@unittest.skipIf(
create_test_server is None, f"Server dependencies not installed: {server_import_fail_message}"
)
class RemoteButlerSqliteRegistryTests(RemoteButlerRegistryTests, unittest.TestCase):
"""Tests for RemoteButler's registry shim, with a SQLite DB backing the
server.
Expand All @@ -209,7 +221,9 @@ class RemoteButlerSqliteRegistryTests(RemoteButlerRegistryTests, unittest.TestCa
postgres = None


@unittest.skipIf(create_test_server is None, "Server dependencies not installed.")
@unittest.skipIf(
create_test_server is None, f"Server dependencies not installed: {server_import_fail_message}"
)
class RemoteButlerPostgresRegistryTests(RemoteButlerRegistryTests, unittest.TestCase):
"""Tests for RemoteButler's registry shim, with a Postgres DB backing the
server.
Expand Down
7 changes: 5 additions & 2 deletions tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,11 @@
from lsst.daf.butler.remote_butler.server import create_app
from lsst.daf.butler.remote_butler.server._dependencies import butler_factory_dependency
from lsst.daf.butler.tests.server import TEST_REPOSITORY_NAME, UnhandledServerError, create_test_server
except ImportError:

reason_text = ""
except ImportError as e:
create_test_server = None
reason_text = str(e)

from unittest.mock import NonCallableMock, patch

Expand All @@ -66,7 +69,7 @@
TESTDIR = os.path.abspath(os.path.dirname(__file__))


@unittest.skipIf(create_test_server is None, "Server dependencies not installed.")
@unittest.skipIf(create_test_server is None, f"Server dependencies not installed: {reason_text}")
class ButlerClientServerTestCase(unittest.TestCase):
"""Test for Butler client/server."""

Expand Down

0 comments on commit 04b15dc

Please sign in to comment.