pytest plugin with sqlalchemy related fixtures
Project description
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
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pytest_sqlalchemy-0.3.0.tar.gz.
File metadata
- Download URL: pytest_sqlalchemy-0.3.0.tar.gz
- Upload date:
- Size: 4.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fcac78fb23fe5741a178118d98dfaaac705172ee5ef600a46d0940255182e664
|
|
| MD5 |
97cf610ee98e03d2a375ebdf6f007acd
|
|
| BLAKE2b-256 |
fe8b10881b6fd1d8edd109e667546d32b3b4b0c0a287a0efafc33d030b25582b
|
Provenance
The following attestation bundles were made for pytest_sqlalchemy-0.3.0.tar.gz:
Publisher:
release.yml on pytest-dev/pytest-sqlalchemy
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pytest_sqlalchemy-0.3.0.tar.gz -
Subject digest:
fcac78fb23fe5741a178118d98dfaaac705172ee5ef600a46d0940255182e664 - Sigstore transparency entry: 199660188
- Sigstore integration time:
-
Permalink:
pytest-dev/pytest-sqlalchemy@61db51b09446d4fe3f69cae3147ab7a559c72b94 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/pytest-dev
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@61db51b09446d4fe3f69cae3147ab7a559c72b94 -
Trigger Event:
workflow_run
-
Statement type:
File details
Details for the file pytest_sqlalchemy-0.3.0-py3-none-any.whl.
File metadata
- Download URL: pytest_sqlalchemy-0.3.0-py3-none-any.whl
- Upload date:
- Size: 5.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ca65ecd26d01df3d44e663831d5e636bd17f87042f507ede4181abcf33382241
|
|
| MD5 |
33014182f4f6c3db5308f879ed2ccee1
|
|
| BLAKE2b-256 |
d7b08730de674b2bd0bb11f23dd20989e21fdec9058056d4c12e11606a379da2
|
Provenance
The following attestation bundles were made for pytest_sqlalchemy-0.3.0-py3-none-any.whl:
Publisher:
release.yml on pytest-dev/pytest-sqlalchemy
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pytest_sqlalchemy-0.3.0-py3-none-any.whl -
Subject digest:
ca65ecd26d01df3d44e663831d5e636bd17f87042f507ede4181abcf33382241 - Sigstore transparency entry: 199660189
- Sigstore integration time:
-
Permalink:
pytest-dev/pytest-sqlalchemy@61db51b09446d4fe3f69cae3147ab7a559c72b94 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/pytest-dev
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@61db51b09446d4fe3f69cae3147ab7a559c72b94 -
Trigger Event:
workflow_run
-
Statement type: