Skip to content

Commit

Permalink
Define module-level fixtures for component tests
Browse files Browse the repository at this point in the history
  • Loading branch information
disrupted committed Jul 23, 2024
1 parent 7c02371 commit fbb9139
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 35 deletions.
31 changes: 31 additions & 0 deletions tests/components/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from unittest import mock

import pytest

from kpops.component_handlers import ComponentHandlers
from kpops.component_handlers.helm_wrapper.model import HelmDiffConfig
from kpops.config import KpopsConfig, TopicNameConfig, set_config
from tests.components import PIPELINE_BASE_DIR


@pytest.fixture(autouse=True, scope="module")
def config() -> None:
config = KpopsConfig(
topic_name_config=TopicNameConfig(
default_error_topic_name="${component.type}-error-topic",
default_output_topic_name="${component.type}-output-topic",
),
kafka_brokers="broker:9092",
helm_diff_config=HelmDiffConfig(),
pipeline_base_dir=PIPELINE_BASE_DIR,
)
set_config(config)


@pytest.fixture(autouse=True, scope="module")
def handlers() -> None:
ComponentHandlers(
schema_handler=mock.AsyncMock(),
connector_handler=mock.AsyncMock(),
topic_handler=mock.AsyncMock(),
)
10 changes: 2 additions & 8 deletions tests/components/test_kafka_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,14 @@ def connector_config(self) -> KafkaConnectorConfig:
)

@pytest.fixture()
def connector(
self,
connector_config: KafkaConnectorConfig,
) -> KafkaConnector:
def connector(self, connector_config: KafkaConnectorConfig) -> KafkaConnector:
return KafkaConnector( # HACK: not supposed to be instantiated, because ABC
name=CONNECTOR_NAME,
config=connector_config,
resetter_namespace=RESETTER_NAMESPACE,
)

def test_connector_config_name_override(
self,
connector: KafkaConnector,
):
def test_connector_config_name_override(self, connector: KafkaConnector):
assert connector.config.name == CONNECTOR_FULL_NAME

connector = KafkaConnector(
Expand Down
27 changes: 0 additions & 27 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,8 @@

import pytest

from kpops.component_handlers import ComponentHandlers
from kpops.component_handlers.helm_wrapper.model import HelmDiffConfig
from kpops.config import KpopsConfig, TopicNameConfig, set_config
from kpops.utils.environment import ENV, Environment
from kpops.utils.yaml import load_yaml_file
from tests.components import PIPELINE_BASE_DIR

logger = logging.getLogger("faker")
logger.setLevel(logging.INFO) # quiet faker locale messages
Expand Down Expand Up @@ -55,26 +51,3 @@ def custom_components():
yield
finally:
shutil.rmtree(dst)


@pytest.fixture(autouse=True, scope="session")
def config() -> None:
config = KpopsConfig(
topic_name_config=TopicNameConfig(
default_error_topic_name="${component.type}-error-topic",
default_output_topic_name="${component.type}-output-topic",
),
kafka_brokers="broker:9092",
helm_diff_config=HelmDiffConfig(),
pipeline_base_dir=PIPELINE_BASE_DIR,
)
set_config(config)


@pytest.fixture(autouse=True, scope="session")
def handlers() -> ComponentHandlers:
return ComponentHandlers(
schema_handler=mock.AsyncMock(),
connector_handler=mock.AsyncMock(),
topic_handler=mock.AsyncMock(),
)

0 comments on commit fbb9139

Please sign in to comment.