improve mongo_is_running stub to check only once per pants run
+from dataclasses import dataclass
+
# TODO: this is planned / does not exist yet
from pants.backend.python.goals.pytest_runner import (
PytestPluginSetupRequest,
PytestPluginSetup,
)
-from pants.engine.rules import collect_rules, rule
+from pants.engine.rules import collect_rules, rule, _uncacheable_rule
from pants.engine.target import Target
from .exceptions import ServiceMissingError
@@ -15,11 +17,22 @@ class UsesMongoRequest(PytestPluginSetupRequest):
return "mongo" in target.get(UsesServicesField).value
-@rule
-def assert_mongo_is_running(request: UsesMongoRequest) -> PytestPluginSetup:
- mongo_is_running = True
+@dataclass(frozen=True)
+class MongoStatus:
+ is_running: bool
+
+
+@_uncacheable_rule
+async def mongo_is_running() -> MongoStatus:
# TODO: logic to determine if it is running
- if not mongo_is_running:
+ # maybe something like https://stackoverflow.com/a/53640204
+ # https://github.com/Lucas-C/dotfiles_and_notes/blob/master/languages/python/mongo_ping_client.py
+ return MongoStatus(True)
+
+
+@rule
+def assert_mongo_is_running(request: UsesMongoRequest, mongo_status: MongoStatus) -> PytestPluginSetup:
+ if not mongo_status.is_running:
platform = "" # TODO: lookup
if platform == "CentOS7":
