fixtures.py 764 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. from unittest.mock import DEFAULT
  2. from unittest.mock import patch
  3. import kafkaesk
  4. import os
  5. import pytest
  6. import uuid
  7. @pytest.fixture()
  8. async def kafka():
  9. yield os.environ.get("KAFKA", "localhost:9092").split(":")
  10. @pytest.fixture()
  11. def topic_prefix():
  12. return uuid.uuid4().hex
  13. @pytest.fixture()
  14. async def app(kafka, topic_prefix):
  15. yield kafkaesk.Application(
  16. [f"{kafka[0]}:{kafka[1]}"],
  17. topic_prefix=topic_prefix,
  18. kafka_settings={
  19. "metadata_max_age_ms": 500,
  20. },
  21. )
  22. @pytest.fixture()
  23. def metrics():
  24. with patch.multiple(
  25. "kafkaesk.app",
  26. PUBLISHED_MESSAGES=DEFAULT,
  27. PRODUCER_TOPIC_OFFSET=DEFAULT,
  28. PUBLISHED_MESSAGES_TIME=DEFAULT,
  29. ) as mock:
  30. yield mock