Pulsar Marker Usage
The @pytest.mark.pulsar marker allows you to create and optionally delete Pulsar topics for the duration of a test. This is useful for isolating test resources and ensuring a clean environment.
Marker Parameters
The following parameters are supported by the pulsar marker:
topics(list[str], required): List of Pulsar topic names to create for the test.delete_after(bool, optional): IfTrue, topics are deleted after the test. Default isFalse. Resources are always cleaned up prior to each test run.service_url(str, optional): Pulsar service URL. Defaults to the value inpytest.inior the plugin default ofpulsar://localhost:6650admin_url(str, optional): Pulsar admin URL. Defaults to the value inpytest.inior the plugin default ofhttp://localhost:8080
Examples:
import pytest
@pytest.mark.pulsar(topics=["test-topic-1", "test-topic-2"])
class TestPulsar:
def test_topic_creation(self):
# Test logic using the created topics
pass
import pytest
@pytest.mark.pulsar(topics=["test-topic-1", "test-topic-2"], delete_after=True)
class TestPulsar:
def test_topic_creation(self):
# Test logic using the created topics
pass
import pytest
@pytest.mark.pulsar(topics=["test-topic-1", "test-topic-2"], delete_after=True, service_url="pulsar://localhost:1234")
class TestPulsar:
def test_topic_creation(self):
# Test logic using the created topics
pass
PyTest.ini Options (Marker Defaults)
You can set default values for marker parameters in your pytest.ini file. These will be used if the marker does not override them.