Skip to main content

Docs PyPI Git

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

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)

Source distribution for pytest-sqlalchemy 0.3.0
File Size Uploaded
pytest_sqlalchemy-0.3.0.tar.gz 4.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pytest-sqlalchemy 0.3.0
File Interpreter ABI Platform
pytest_sqlalchemy-0.3.0-py3-none-any.whl Python 3 none any Details

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 log

Release 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 log

Release history Release notifications | RSS feed

This release

0.3.0 This release

2 release files

0.2.1

1 release file

0.2.0

1 release file

0.1.1

1 release file

0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page