pants: combine mongo_is_running rules
-from dataclasses import dataclass
-
from textwrap import dedent
from pants.backend.python.goals.pytest_runner import (
@@ -34,13 +32,9 @@ class UsesMongoRequest(PytestPluginSetupRequest):
return uses is not None and "mongo" in uses
-@dataclass(frozen=True)
-class MongoStatus:
- is_running: bool
-
-
@rule(desc="Test to see if mongodb is running and accessible for tests.")
-async def mongo_is_running() -> MongoStatus:
+async def mongo_is_running(request: UsesMongoRequest, platform: Platform) -> PytestPluginSetup:
+
# These config opts are used via oslo_config.cfg.CONF.database.{host,port,db_name,connection_timeout}
# These config opts currently hard-coded in:
# for unit tests: st2tests/st2tests/config.py
@@ -101,14 +95,11 @@ async def mongo_is_running() -> MongoStatus:
level=LogLevel.DEBUG,
)
)
- return MongoStatus(result.exit_code == 0)
+ is_running = result.exit_code == 0
+ if is_running:
+ return PytestPluginSetup()
-@rule("Report that mongodb is required for test runs.")
-async def assert_mongo_is_running(
- request: UsesMongoRequest, mongo_status: MongoStatus, platform: Platform
-) -> PytestPluginSetup:
- if not mongo_status.is_running:
if platform.distro in ["centos", "rhel"] or "rhel" in platform.distro_like:
instructions = dedent(
f"""\
@@ -223,8 +214,6 @@ async def assert_mongo_is_running(
raise ServiceMissingError("mongo", platform, instructions)
- return PytestPluginSetup()
-
def rules():
return [
