testcontainers-python — удобная библиотека для использования Docker-контейнеров при функциональном и интеграционном тестировании на Python.
from testcontainers.postgres import PostgresContainer
import sqlalchemy
with PostgresContainer("postgres:16") as postgres:
engine = sqlalchemy.create_engine(postgres.get_connection_url())
with engine.begin() as connection:
result = connection.execute(sqlalchemy.text("select version()"))
version, = result.fetchone()
print(version) # PostgreSQL 16...
Этот пример поднимает базу данных Postgres в Docker-контейнере. Метод get_connection_url() возвращает URL, совместимый с SQLAlchemy, чтобы подключиться к базе и получить версию.
#Python #Docker #Testcontainers #Тестирование #PostgreSQL #ИнтеграционныеТесты #DevOps #Backend #Разработка
https://github.com/testcontainers/testcontainers-python
Please open Telegram to view this post
VIEW IN TELEGRAM
GitHub
GitHub - testcontainers/testcontainers-python: Testcontainers is a Python library that providing a friendly API to run Docker container.…
Testcontainers is a Python library that providing a friendly API to run Docker container. It is designed to create runtime environment to use during your automatic tests. - testcontainers/testconta...
👍13 5 5