SQLAlchemy related fixtures to handle connections and transactions with SQLAlchemy in tests.
Fixtures
This plugin provides the following fixtures which gives access to the SQLAlchemy objects of the same name.
engine The engine used to connect to the database. Scope is “module”.
connection An open connection to the database. Scope is “module”.
See Working with Engines and Connections on how to use these fixtures.
transaction A started transaction on the connection. Transaction will be rolled back. No Scope.
See Using Transactions on how to use this fixtures
dbsession A sqlalchemy session not bound to any model. No scope.
See Session Basics to learn about how to use sessions.
Usage
The fixtures can be used in your tests like any other Pytest Fixtures.
Example:
import pytest
from pytest_sqlalchemy import connection
def test_connection(connection):
# Do fancy stuff with the connection.
# Note you will not need to close the connection. This is done
# automatically when the scope (module) of the fixtures ends.
assert connection
Invoke
You need to provide the connection URL for the engine when invoking the pytest command:
pytest --sqlalchemy-connect-url="postgresql://scott:tiger@localhost:5432/mydatabase"
Or override the sqlalchemy_connect_url fixture on your conftest.py file:
@pytest.fixture(scope="session")
def sqlalchemy_connect_url():
return 'postgresql://scott:tiger@localhost:5432/mydatabase'
Development
To get going, in a checkout:
uv sync
You can then run the tests with:
uv run pytest
Metadata
Release files for pytest-sqlalchemy 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pytest_sqlalchemy-0.3.0.tar.gz | 4.8 kB | With provenance | Details for pytest_sqlalchemy-0.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pytest_sqlalchemy-0.3.0-py3-none-any.whl | Python 3 | none | any | Details for pytest_sqlalchemy-0.3.0-py3-none-any.whl |
Total release size: 10.3 kB
Release files / pytest_sqlalchemy-0.3.0.tar.gz
| Download URL | pytest_sqlalchemy-0.3.0.tar.gz |
|---|---|
| Size | 4.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fcac78fb23fe5741a178118d98dfaaac705172ee5ef600a46d0940255182e664
|
|
BLAKE2b-256 checksum How to use checksums |
fe8b10881b6fd1d8edd109e667546d32b3b4b0c0a287a0efafc33d030b25582b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Apr 19, 2025.
Transparency logRelease files / pytest_sqlalchemy-0.3.0-py3-none-any.whl
| Download URL | pytest_sqlalchemy-0.3.0-py3-none-any.whl |
|---|---|
| Size | 5.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ca65ecd26d01df3d44e663831d5e636bd17f87042f507ede4181abcf33382241
|
|
BLAKE2b-256 checksum How to use checksums |
d7b08730de674b2bd0bb11f23dd20989e21fdec9058056d4c12e11606a379da2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Apr 19, 2025.
Transparency logSecurity for pytest-sqlalchemy 0.3.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for pytest_sqlalchemy-0.3.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Apr 19, 2025.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.