Best Python code snippet using testcontainers-python_python
file.py
Source:file.py
...65 def __init__(self, _: str):66 self._setup_minio()67 def _setup_minio(self):68 self.minio = DockerContainer(self.minio_image)69 self.minio.with_exposed_ports(9000).with_exposed_ports(9001).with_env(70 "MINIO_ROOT_USER", self.access_key71 ).with_env("MINIO_ROOT_PASSWORD", self.secret).with_command(72 'server /data --console-address ":9001"'73 )74 self.minio.start()75 log_string_to_wait_for = (76 "API" # The minio container will print "API: ..." when ready.77 )78 wait_for_logs(container=self.minio, predicate=log_string_to_wait_for, timeout=5)79 def _upload_parquet_file(self, df, file_name, minio_endpoint):80 self.f = tempfile.NamedTemporaryFile(suffix=".parquet", delete=False)81 df.to_parquet(self.f.name)82 client = Minio(83 minio_endpoint,...
conftest.py
Source:conftest.py
...14from app import create_app, db as the_db15@pytest.fixture(scope="class")16def redis() -> DockerContainer:17 print("Crée un conteneur redis")18 with DockerContainer("redis:7.0.4-alpine").with_exposed_ports(6379) as redis:19 yield redis20@pytest.fixture(scope="class")21def mariadb(request) -> DockerContainer:22 data_dir = Path(__file__).parent.resolve() / "data"23 init_db_dir = data_dir / "mariadb" / "initdb.d"24 ddl_fp = init_db_dir / "001-ddl-db.sql"25 data_fp = init_db_dir / "002-empty.sql"26 node = request.node27 marker = node.get_closest_marker('jeu_de_donnees')28 if marker is not None and str(marker.args[0]) == "donnees_variees_de_prod":29 data_fp = init_db_dir / "010-various-data-from-prod.sql"30 print(f"Initialisation de la base avec le jeu de données {data_fp}")31 with DockerContainer("mariadb:5.5") \32 .with_exposed_ports(3306) \33 .with_env("MYSQL_ROOT_PASSWORD", "password") \34 .with_env("MYSQL_DATABASE", "data_extraction") \35 .with_env("MYSQL_USER", "datauser") \36 .with_env("MYSQL_PASSWORD", "password") \37 .with_volume_mapping(str(ddl_fp), "/docker-entrypoint-initdb.d/001-ddl.sql") \38 .with_volume_mapping(str(data_fp), "/docker-entrypoint-initdb.d/002-data.sql") as database:39 wait_for_logs(database, "port: 3306")40 yield database41@pytest.fixture(scope="class")42def solr(request) -> DockerContainer:43 solr_volumes_dir = Path(__file__).parent.resolve() / "data" / "solr" / "volumes"44 node = request.node45 marker = node.get_closest_marker('jeu_de_donnees')46 47 # Gestion du jeu de donnees48 var_solr_dp = None49 if marker is not None and str(marker.args[0]) == "donnees_variees_de_prod":50 var_solr_dp = solr_volumes_dir / "donnees_variees_de_prod" / "var" / "solr"51 #52 container = DockerContainer("registry.csm.ovh:443/csm/open-data/solr/develop:latest")53 container = container.with_exposed_ports("8983") \54 .with_command("solr-precreate publication_core server/solr/configsets/publication_config/")55 56 with tempfile.TemporaryDirectory("it_solr_tempdir") as tmp_dir:57 58 if var_solr_dp is not None:59 print(f"Utilisation de solr avec un jeu de données: {var_solr_dp}")60 vol_dp = shutil.copytree(var_solr_dp, Path(tmp_dir) / "var_lib_solr")61 container = container.with_volume_mapping(str(vol_dp), "/var/solr", "rw")62 else:63 print(f"Utilisation de solr sans jeu de données")64 65 with container as solr_container:66 wait_for_logs(solr_container, "SolrCore [publication_core]", 60)67 yield solr_container...
basic.py
Source:basic.py
...3import requests4import time5opensearch = DockerContainer("opensearchproject/opensearch:2.2.0")6opensearch.with_env("discovery.type", "single-node")7opensearch.with_exposed_ports(9200)8def get_url(opensearch):9 return f"http://{opensearch.get_container_host_ip()}:{opensearch.get_exposed_port(9200)}"10@wait_container_is_ready(requests.exceptions.ConnectionError, requests.exceptions.ReadTimeout)11def _connect(opensearch):12 url = get_url(opensearch)13 response = requests.get("{}/_plugins/_security/health".format(url), timeout=1)14 response.raise_for_status()15with opensearch:16 print("our url =", get_url(opensearch))17 time.sleep(5)18 print('done')19#20# opensearch = DockerContainer('opensearchproject/opensearch:2.2.0')21# opensearch.with_env("discovery.type", "single-node")22# opensearch.with_exposed_ports(9200)...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!