Skip to main content

pytest plugin with sqlalchemy related fixtures

Project description

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

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

pytest_sqlalchemy-0.3.0.tar.gz (4.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pytest_sqlalchemy-0.3.0-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

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

Hashes for pytest_sqlalchemy-0.3.0.tar.gz
Algorithm Hash digest
SHA256 fcac78fb23fe5741a178118d98dfaaac705172ee5ef600a46d0940255182e664
MD5 97cf610ee98e03d2a375ebdf6f007acd
BLAKE2b-256 fe8b10881b6fd1d8edd109e667546d32b3b4b0c0a287a0efafc33d030b25582b

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytest_sqlalchemy-0.3.0.tar.gz:

Publisher: release.yml on pytest-dev/pytest-sqlalchemy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pytest_sqlalchemy-0.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for pytest_sqlalchemy-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ca65ecd26d01df3d44e663831d5e636bd17f87042f507ede4181abcf33382241
MD5 33014182f4f6c3db5308f879ed2ccee1
BLAKE2b-256 d7b08730de674b2bd0bb11f23dd20989e21fdec9058056d4c12e11606a379da2

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page