pytest_kafka.install module

Utility methods for downloading Kafka locally.

pytest_kafka.install.clean_kafka(kafka_dir: str | Path = 'kafka', kafka_tar_rootdir: str | Path | None = None, kafka_tar: str | Path = 'kafka.tgz') None[source]

Clean whatever set_up_kafka may create.

pytest_kafka.install.expected_archive_root_dir(kafka_url: str) str[source]

Determine the expected archive root directory name.

>>> url = 'https://archive.apache.org/dist/kafka/3.8.0/kafka_2.13-3.8.0.tgz'
>>> expected_archive_root_dir(url)
'kafka_2.13-3.8.0'
pytest_kafka.install.set_up_kafka(kafka_url: str = 'https://archive.apache.org/dist/kafka/3.2.3/kafka_2.13-3.2.3.tgz', extract_location: str = '.', kafka_dir: str = 'kafka', kafka_tar: str = 'kafka.tgz', kafka_tar_rootdir: str | None = None) None[source]

Clean, download Kafka from an official mirror and untar it.

Parameters:
  • kafka_url – URL to download Kafka archive from

  • extract_location – local directory to extract the Kafka archive to

  • kafka_dir – directory name to rename the in-archive Kafka distribution directory to

  • kafka_tar – file name of the downloaded Kafka archive

  • kafka_tar_rootdir – expected name of the root directory in the Kafka archive, which contains the Kafka distribution. If None, it will be the URL file name without a suffix.

The kafka_dir, kafka_tar and kafka_tar_rootdir arguments are relative to the extract_location argument so that calling setup_kafka(extract_location='/opt/local', kafka_dir='my_kafka') will result in Kafka being installed into /opt/local/my_kafka