Closed ewaldmikolaj closed 3 months ago
this works for me:
mkdir issues-605
cd issues-605
python -m venv .venv
. $_/bin/activate
pip install testcontainers==4.5.1 confluent-kafka==2.4.0 pytest==8.2.2
vim test.py
import os
import pytest
import time
from testcontainers.kafka import KafkaContainer
from confluent_kafka.admin import AdminClient, NewTopic
@pytest.fixture(scope="module", autouse=True)
def kafka(request):
kafka = KafkaContainer()
kafka.start()
def teardown():
kafka.stop()
request.addfinalizer(teardown)
os.environ["BOOTSTRAP"] = kafka.get_bootstrap_server()
def test():
admin_client = AdminClient({"bootstrap.servers": os.environ["BOOTSTRAP"]})
topics = admin_client.create_topics([NewTopic("test-topic", 1, 1)])
time.sleep(15)
assert admin_client.list_topics().topics != [] # changed this line
I created a new python env and it also worked. Thanks for feedback. I will close this question.
What are you trying to do?
Hello, I am trying to deploy Kafka Container, connect to it and create some test topic, which then can I use in integration tests. I am struggling with connection to Container. It works fine, when I use docker compose prepared by Confluent and described here. When creating a container using library, I can't authenticate.
The error message that I am getting is:
Should I expose some ports and pass env variables to make it work?
Where are you trying to do it?
The last assert is just to test connection, and check what's returned by list_topics() function.
Runtime environment
Provide a summary of your runtime environment. Which operating system, python version, and docker version are you using? What is the version of
testcontainers-python
you are using? You can run the following commands to get the relevant information.