Database testing fixtures using the SQLAlchemy asyncio API
Project description
pytest-async-sqlalchemy
Database testing fixtures using the SQLAlchemy asyncio API
You can install "pytest-async-sqlalchemy" via pip from PyPI
$ pip install pytest-async-sqlalchemy
Setup
pytest-async-sqlalchemy
provides placeholders to configure and initialize
the testing database: database_url
and init_database
. These two must be
defined in your project conftest.py
like below:
@pytest.fixture(scope="session")
def database_url():
return "postgresql+asyncpg://postgres:masterkey@localhost/dbtest"
@pytest.fixture(scope="session")
def init_database():
from myprorject.db import metadata
return metadata.create_all
The database_url
must be a session-scoped fixture that returns the database URI.
init_database
must also be a session-scoped fixture that returns the callable used
to initialize the database (in most cases, this would return the
metadata.create_all
function).
Usage
This plugin provides the following fixtures:
dbsession
: AnAsyncSession
object bounded to the test database. Database changes are discarded after each test function, so the same database is used for the entire test suite (avoiding the overhead of initializing a database on every test).database
:database
provides a new database within the scope of the test function. The value of the fixture is a string URL pointing to the database.
Contributing
Contributions are very welcome. Tests can be run with tox, please ensure the coverage at least stays the same before you submit a pull request.
License
Distributed under the terms of the MIT license, "pytest-async-sqlalchemy" is free and open source software
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for pytest-async-sqlalchemy-0.1.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 436957239724c164e5b219064d836b2ad8fa1ea2c2d6c2219a9f2249898806d4 |
|
MD5 | 8533682cfc6b3573058ef3c2bec707d3 |
|
BLAKE2b-256 | f69ff697c8700dc73e9c53a8350c9ac7c7e2114961bcdd348cd7c7305e61a578 |
Hashes for pytest_async_sqlalchemy-0.1.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dcde441f435b5db0f1cc6ed155872c8d1bcedeb7f944942abade9c51bf098046 |
|
MD5 | 993f9b9060215c8d66e7b3e946964f0c |
|
BLAKE2b-256 | e81a1d1f0dc20811e066de71b9202bb414d291e253c3fd7005d9938656bb9edd |