Skip to content

Commit 2b7ec62

Browse files
authored
Merge pull request #16 from cjw296/docs
Initial documentation
2 parents a076961 + 44245be commit 2b7ec62

File tree

8 files changed

+163
-63
lines changed

8 files changed

+163
-63
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ jobs:
8888
cache-suffix: ${{ matrix.uv-resolution }}
8989

9090
- name: Install the project and dependencies
91-
run: uv sync --all-extras --dev --resolution ${{ matrix.uv-resolution }}
91+
run: uv sync --dev --resolution ${{ matrix.uv-resolution }}
9292

9393
- name: Run tests
9494
run: |
@@ -134,7 +134,7 @@ jobs:
134134
cache-dependency-glob: "**/pyproject.toml"
135135

136136
- name: Install the project
137-
run: uv sync --all-extras --dev
137+
run: uv sync --dev
138138

139139
- name: Run tests
140140
run: uv run mypy pytest_sqlalchemy.py tests

.readthedocs.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
version: 2
2+
3+
build:
4+
os: ubuntu-24.04
5+
tools:
6+
python: "3.13"
7+
jobs:
8+
create_environment:
9+
- asdf plugin add uv
10+
- asdf install uv latest
11+
- asdf global uv latest
12+
install:
13+
- uv sync --group docs
14+
build:
15+
html:
16+
- uv run sphinx-build -T -b html docs $READTHEDOCS_OUTPUT/html
17+
18+
sphinx:
19+
configuration: docs/conf.py
20+
fail_on_warning: true

README.md

Lines changed: 0 additions & 61 deletions
This file was deleted.

README.rst

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
pytest-sqlalchemy
2+
=================
3+
4+
|Docs|_ |PyPI|_ |Git|_
5+
6+
.. |Docs| image:: https://readthedocs.org/projects/pytest-sqlalchemy/badge/?version=latest
7+
.. _Docs: https://pytest-sqlalchemy.readthedocs.io/
8+
9+
.. |PyPI| image:: https://badge.fury.io/py/pytest-sqlalchemy.svg
10+
.. _PyPI: https://pypi.org/project/pytest-sqlalchemy/
11+
12+
.. |Git| image:: https://github.com/toirl/pytest-sqlalchemy/actions/workflows/ci.yml/badge.svg
13+
.. _Git: https://github.com/toirl/pytest-sqlalchemy
14+
15+
SQLAlchemy related fixtures to handle connections and transactions with SQLAlchemy in tests.
16+
17+
Fixtures
18+
--------
19+
This plugin provides the following fixtures which gives access to the SQLAlchemy objects of the same
20+
name.
21+
22+
* **engine** The engine used to connect to the database. Scope is "module".
23+
* **connection** An open connection to the database. Scope is "module".
24+
25+
See `Working with Engines and Connections`__ on how to use these fixtures.
26+
27+
__ http://docs.sqlalchemy.org/en/latest/core/connections.html#module-sqlalchemy.engine
28+
29+
* **transaction** A started transaction on the connection. Transaction will be rolled back.
30+
No Scope.
31+
32+
See `Using Transactions`__ on how to use this fixtures
33+
34+
__ http://docs.sqlalchemy.org/en/latest/core/connections.html#using-transactions
35+
36+
* **dbsession** A sqlalchemy session *not* bound to any model. No scope.
37+
38+
See `Session Basics`__ to learn about how to use sessions.
39+
40+
__ http://docs.sqlalchemy.org/en/latest/orm/session_basics.html#session-basics
41+
42+
Usage
43+
-----
44+
The fixtures can be used in your tests like any other `Pytest Fixtures`__.
45+
46+
__ https://docs.pytest.org/en/3.6.1/fixture.html
47+
48+
**Example**:
49+
50+
.. code-block:: python
51+
52+
import pytest
53+
from pytest_sqlalchemy import connection
54+
55+
def test_connection(connection):
56+
# Do fancy stuff with the connection.
57+
# Note you will not need to close the connection. This is done
58+
# automatically when the scope (module) of the fixtures ends.
59+
assert connection
60+
61+
Invoke
62+
------
63+
You need to provide the connection URL for the engine when invoking the pytest command:
64+
65+
.. code-block:: bash
66+
67+
pytest --sqlalchemy-connect-url="postgresql://scott:tiger@localhost:5432/mydatabase"
68+
69+
Or override the ``sqlalchemy_connect_url`` fixture on your ``conftest.py`` file:
70+
71+
.. code-block:: python
72+
73+
@pytest.fixture(scope="session")
74+
def sqlalchemy_connect_url():
75+
return 'postgresql://scott:tiger@localhost:5432/mydatabase'
76+
77+
Development
78+
----------
79+
80+
To get going, in a checkout:
81+
82+
.. code-block:: bash
83+
84+
uv sync
85+
86+
You can then run the tests with:
87+
88+
.. code-block:: bash
89+
90+
uv run pytest

docs/Makefile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Minimal makefile for Sphinx documentation
2+
#
3+
4+
# You can set these variables from the command line, and also
5+
# from the environment for the first two.
6+
SPHINXOPTS ?=
7+
SPHINXBUILD ?= uv run sphinx-build
8+
SOURCEDIR = .
9+
BUILDDIR = _build
10+
11+
# Put it first so that "make" without argument is like "make help".
12+
help:
13+
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
14+
15+
.PHONY: help Makefile
16+
17+
# Catch-all target: route all unknown targets to Sphinx using the new
18+
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
19+
%: Makefile
20+
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

docs/conf.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from importlib import metadata
2+
3+
extensions = [
4+
'sphinx.ext.autodoc',
5+
'sphinx.ext.intersphinx',
6+
]
7+
8+
intersphinx_mapping = {
9+
'python': ('http://docs.python.org', None),
10+
}
11+
12+
project = 'pytest-sqlalchemy'
13+
author = 'Torsten Irländer'
14+
release = metadata.version(project)
15+
copyright = f'2015 onwards {author}'
16+
17+
templates_path = ['_templates']
18+
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
19+
20+
autodoc_member_order = 'bysource'
21+
22+
html_theme = 'furo'
23+
24+
nitpicky = True
25+
nitpick_ignore: list[tuple[str, str]] = []

docs/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.. include:: ../README.rst

pyproject.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ dev = [
3232
"mypy>=1.15.0",
3333
"pytest-xdist>=3.6.1",
3434
]
35+
docs = [
36+
"furo>=2024.8.6",
37+
# work around https://github.com/astral-sh/uv/issues/12737
38+
"sphinx>=7.4.7",
39+
]
3540

3641
[build-system]
3742
requires = ["setuptools>=61.0"]

0 commit comments

Comments
 (0)