https://github.com/pythoninthegrass/test_containers
Suite of examples on how to use testcontainers with python
https://github.com/pythoninthegrass/test_containers
python testcontainers
Last synced: 11 months ago
JSON representation
Suite of examples on how to use testcontainers with python
- Host: GitHub
- URL: https://github.com/pythoninthegrass/test_containers
- Owner: pythoninthegrass
- Created: 2024-10-24T02:01:44.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-02-07T23:16:12.000Z (12 months ago)
- Last Synced: 2025-02-21T21:49:55.690Z (11 months ago)
- Topics: python, testcontainers
- Language: Python
- Homepage:
- Size: 39.1 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# test_containers
Suite of examples on how to use [testcontainers](https://testcontainers.com/getting-started/) with [Python](https://testcontainers-python.readthedocs.io/en/latest/).
## Minimum Requirements
* macOS 14+
* Linux _should_ work 🤞
* [Python 3.11+](https://www.python.org/downloads/)
* [Poetry](https://python-poetry.org/docs/)
* [Docker](https://docs.docker.com/get-docker/)
## Recommended Requirements
* [asdf](https://asdf-vm.com/#/)
## Setup
```bash
# Clone the repository
git clone https://github.com/pythoninthegrass/test_containers.git
cd test_containers
# Create a virtual environment
python -m venv .venv
# Activate the virtual environment
source .venv/bin/activate
# Install dependencies
## macos
./bin/build.py # install freetds and compile flags for `pymssql`
## all
poetry install
```
## Quickstart
> [!NOTE]
> There is a [helper script](bin/download.py) in the `bin` directory to download the AdventureWorks2017.bak file. This file is used to restore the database in the examples.
>
> Run via `./bin/download.py ./examples/db/ms_sql/aw_lt_2017.bak`
>
> The URL is found at [AdventureWorks sample databases - SQL Server | Microsoft Learn](https://learn.microsoft.com/en-us/sql/samples/adventureworks-install-configure?view=sql-server-ver15&tabs=ssms#download-backup-files).
```bash
# ms sql
cd examples/db/ms_sql/
λ ./main.py
using host tcp://127.0.0.1:57781
Starting MSSQL container...
...
Restoring database...
Verifying database restore...
Restored tables:
- ErrorLog
- BuildVersion
- Address
- Customer
- CustomerAddress
- Product
- ProductCategory
- ProductDescription
- ProductModel
- ProductModelProductDescription
- SalesOrderDetail
- SalesOrderHeader
Database restored successfully!
Press Enter to stop the container...
Stopping container...
```
## TODO
* Write a test that uses a testcontainer
* Add taskfile for task runners
* Add more examples
* MongoDB
* Postgres
* Redis
* Kafka
* Elasticsearch