https://github.com/litestar-org/pytest-databases
Reusable database fixtures for any and all databases.
https://github.com/litestar-org/pytest-databases
Last synced: 20 days ago
JSON representation
Reusable database fixtures for any and all databases.
- Host: GitHub
- URL: https://github.com/litestar-org/pytest-databases
- Owner: litestar-org
- License: mit
- Created: 2024-03-26T21:28:30.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-05-02T07:51:20.000Z (over 1 year ago)
- Last Synced: 2024-05-02T23:11:54.988Z (over 1 year ago)
- Language: Python
- Size: 2.09 MB
- Stars: 11
- Watchers: 4
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.rst
- License: LICENSE
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
- awesome-python-testing - pytest-databases - Reusable database fixtures for any and all databases. (Tools)
README
| Project | | Status |
| --------- | :-- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| CI/CD | | [](https://github.com/litestar-org/pytest-databases/actions/workflows/release.yaml) [](https://github.com/litestar-org/pytest-databases/actions/workflows/ci.yaml) [](https://github.com/litestar-org/pytest-databases/actions/workflows/docs.yml) |
| Quality | | [](https://codecov.io/github/litestar-org/pytest-databases) [](https://sonarcloud.io/summary/new_code?id=litestar-org_pytest-databases) [](https://sonarcloud.io/summary/new_code?id=litestar-org_pytest-databases) [](https://sonarcloud.io/summary/new_code?id=litestar-org_pytest-databases) [](https://sonarcloud.io/summary/new_code?id=litestar-org_pytest-databases) |
| Package | | [](https://badge.fury.io/py/pytest-databases)  |
| Community | | [](https://discord.gg/litestar-919193495116337154) [](https://matrix.to/#/#litestar:matrix.org) [](https://blog.litestar.dev) [](https://twitter.com/LitestarAPI) [](https://blog.litestar.dev) |
| Meta | | [](https://github.com/litestar-org/pytest-databases) [](https://github.com/python/mypy) [](https://spdx.org/licenses/) [](https://github.com/sponsors/litestar-org) [](https://github.com/astral-sh/ruff) [](https://github.com/psf/black) |
# Pytest Databases
Ready-made database fixtures for your pytest tests.
## Features
- 🚀 Easy-to-use database fixtures
- 🔄 Support for multiple database types
- 🐳 Docker integration for isolated testing environments
- ⚡ Fast and efficient test execution
- 🔧 Highly configurable
`pytest-databases` uses the Docker Python SDK to manage the startup and shutdown of database services in containers. The following databases are currently available:
- **Postgres**: Version 12, 13, 14, 15, 16, 17 and 18 are available
- **MySQL**: Version 5.6, 5.7 and 8 are available
- **Oracle**: Version 18c XE and 23C Free are available
- **SQL Server**: Version 2022 is available
- **Google AlloyDB Omni**: Simplified Omni installation for easy testing.
- **Google Spanner**: The latest cloud-emulator from Google is available
- **Google BigQuery**: Unofficial BigQuery emulator
- **CockroachDB**: Version latest is available
- **Redis**: Latest version
- **Valkey**: Latest version
- **Dragonfly**: Latest version
- **KeyDB**: Latest version
- **Elasticsearch**: Version 7 and 8 are available
- **Azure blob storage**: Via azurite
- **Minio**: Latest version
## Installation
Quick install for postgres:
```bash
pip install pytest-databases[postgres]
```
## Quick Start
- Add to your pytest `conftest.py`:
```py
pytest_plugins = ["pytest_databases.docker.postgres"]
```
- Use in your tests:
```python
from pytest_databases.docker.postgres import PostgresService
import psycopg
def test_one(postgres_service: PostgresService) -> None:
with psycopg.connect(
f"postgresql://{postgres_service.user}:{postgres_service.password}@{postgres_service.host}:{postgres_service.port}/{postgres_service.database}",
autocommit=True,
) as conn:
result = conn.execute("SELECT 1")
assert result
```
## Documentation
Full documentation is available at [https://litestar-org.github.io/pytest-databases/latest/](https://litestar-org.github.io/pytest-databases/latest/)
## Contributing
Contributions are welcome! Please read our [Contributing Guide](CONTRIBUTING.md) for details on our code of conduct and the process for submitting pull requests.
## License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
## Acknowledgments
- The Litestar Framework team
- The pytest community