Skip to content

Commit b949331

Browse files
committed
docs(ext): Add sphinx-autodoc-pytest-fixtures demo page and extensions hub
why: The extension's badge system, fixture cards, and index tables need a visual reference page for verifying rendering across themes and modes. what: - Add docs/extensions/ hub with grid cards for all workspace packages - Add badge demo page with autofixture-index table and all badge permutations (scope, kind, autouse, deprecated, combinations) - Add docs/_ext/spf_demo_fixtures.py with synthetic fixtures for demos - Use eval-rst blocks for autofixture directives (autodoc generates RST that MyST cannot process as a native directive) - Register sphinx_autodoc_pytest_fixtures as extra_extensions in conf.py - Add extensions/index to docs toctree
1 parent 1f6e2b8 commit b949331

5 files changed

Lines changed: 231 additions & 0 deletions

File tree

docs/_ext/spf_demo_fixtures.py

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
"""Synthetic fixtures for the sphinx_autodoc_pytest_fixtures badge demo page.
2+
3+
Each fixture exercises one badge-slot combination so the demo page can show
4+
every permutation side-by-side:
5+
6+
Scope: session | module | class | function (suppressed — no badge)
7+
Kind: resource (suppressed) | factory | override_hook
8+
State: autouse | deprecated (set via RST :deprecated: option)
9+
Combos: session+factory, session+autouse
10+
11+
These fixtures are purely for documentation; they are never collected by
12+
pytest during a real test run (the module is not in the test tree).
13+
"""
14+
15+
from __future__ import annotations
16+
17+
import pytest
18+
19+
20+
@pytest.fixture
21+
def demo_plain() -> str:
22+
"""Plain function-scope resource. Shows FIXTURE badge only."""
23+
return "plain"
24+
25+
26+
@pytest.fixture(scope="session")
27+
def demo_session() -> str:
28+
"""Session-scoped resource. Shows SESSION + FIXTURE badges."""
29+
return "session"
30+
31+
32+
@pytest.fixture(scope="module")
33+
def demo_module() -> str:
34+
"""Module-scoped resource. Shows MODULE + FIXTURE badges."""
35+
return "module"
36+
37+
38+
@pytest.fixture(scope="class")
39+
def demo_class() -> str:
40+
"""Class-scoped resource. Shows CLASS + FIXTURE badges."""
41+
return "class"
42+
43+
44+
@pytest.fixture
45+
def demo_factory() -> type[str]:
46+
"""Return a callable (factory kind). Shows FACTORY + FIXTURE badges."""
47+
return str
48+
49+
50+
@pytest.fixture
51+
def demo_override_hook() -> str:
52+
"""Override hook — customise in conftest.py. Shows OVERRIDE + FIXTURE badges."""
53+
return "override"
54+
55+
56+
@pytest.fixture(autouse=True)
57+
def demo_autouse() -> None:
58+
"""Autouse fixture. Shows AUTO + FIXTURE badges."""
59+
60+
61+
@pytest.fixture
62+
def demo_deprecated() -> str:
63+
"""Return a value (deprecated since 1.0, replaced by demo_plain).
64+
65+
This fixture is documented with the ``deprecated`` RST option so the
66+
demo page can show the DEPRECATED + FIXTURE badge combination.
67+
"""
68+
return "deprecated"
69+
70+
71+
@pytest.fixture(scope="session")
72+
def demo_session_factory() -> type[str]:
73+
"""Session-scoped factory. Shows SESSION + FACTORY + FIXTURE badges."""
74+
return str
75+
76+
77+
@pytest.fixture(scope="session", autouse=True)
78+
def demo_session_autouse() -> None:
79+
"""Session-scoped autouse. Shows SESSION + AUTO + FIXTURE badges."""

docs/conf.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
sys.path.insert(0, str(project_root / "packages" / "gp-sphinx" / "src"))
1212
sys.path.insert(0, str(project_root / "packages" / "sphinx-fonts" / "src"))
1313
sys.path.insert(0, str(project_root / "packages" / "sphinx-gptheme" / "src"))
14+
sys.path.insert(
15+
0, str(project_root / "packages" / "sphinx-autodoc-pytest-fixtures" / "src")
16+
)
17+
sys.path.insert(0, str(cwd / "_ext")) # spf_demo_fixtures for badge demo
1418

1519
import gp_sphinx # noqa: E402
1620
from gp_sphinx.config import merge_sphinx_config # noqa: E402
@@ -22,6 +26,8 @@
2226
source_repository=f"{gp_sphinx.__github__}/",
2327
docs_url=gp_sphinx.__docs__,
2428
source_branch="master",
29+
extra_extensions=["sphinx_autodoc_pytest_fixtures"],
30+
pytest_fixture_lint_level="none",
2531
rediraffe_redirects="redirects.txt",
2632
intersphinx_mapping={
2733
"py": ("https://docs.python.org/", None),

docs/extensions/index.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Extensions
2+
3+
Workspace packages that ship as independent Sphinx extensions.
4+
5+
::::{grid} 1 1 2 2
6+
:gutter: 2 2 3 3
7+
8+
:::{grid-item-card} sphinx-autodoc-pytest-fixtures
9+
:link: sphinx-autodoc-pytest-fixtures
10+
:link-type: doc
11+
Autodocumenter for pytest fixtures with scope badges, dependency
12+
tracking, and usage snippets.
13+
:::
14+
15+
:::{grid-item-card} sphinx-fonts
16+
Self-hosted web fonts via Fontsource CDN with `@font-face` injection
17+
and preload hints.
18+
:::
19+
20+
:::{grid-item-card} sphinx-gptheme
21+
Furo child theme with custom sidebar, SPA navigation, and IBM Plex
22+
typography.
23+
:::
24+
25+
:::{grid-item-card} sphinx-argparse-neo
26+
Argparse CLI documentation with `.. argparse::` directive and epilog
27+
transformation.
28+
:::
29+
30+
::::
31+
32+
```{toctree}
33+
:hidden:
34+
35+
sphinx-autodoc-pytest-fixtures
36+
```
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
# sphinx-autodoc-pytest-fixtures
2+
3+
Sphinx extension that documents pytest fixtures as first-class domain objects
4+
with scope badges, dependency tracking, and auto-generated usage snippets.
5+
6+
## Badge demo
7+
8+
Visual reference for all badge permutations. Use this page to verify badge
9+
rendering across themes, zoom levels, and light/dark modes.
10+
11+
```{py:module} spf_demo_fixtures
12+
```
13+
14+
### Fixture index
15+
16+
```{autofixture-index} spf_demo_fixtures
17+
```
18+
19+
---
20+
21+
### Plain (FIXTURE badge only)
22+
23+
Function scope, resource kind, not autouse. Shows only the green FIXTURE badge.
24+
25+
```{eval-rst}
26+
.. autofixture:: spf_demo_fixtures.demo_plain
27+
```
28+
29+
---
30+
31+
### Scope badges
32+
33+
#### Session scope
34+
35+
```{eval-rst}
36+
.. autofixture:: spf_demo_fixtures.demo_session
37+
```
38+
39+
#### Module scope
40+
41+
```{eval-rst}
42+
.. autofixture:: spf_demo_fixtures.demo_module
43+
```
44+
45+
#### Class scope
46+
47+
```{eval-rst}
48+
.. autofixture:: spf_demo_fixtures.demo_class
49+
```
50+
51+
---
52+
53+
### Kind badges
54+
55+
#### Factory kind
56+
57+
Return type `type[str]` is auto-detected as factory — no explicit `:kind:` needed.
58+
59+
```{eval-rst}
60+
.. autofixture:: spf_demo_fixtures.demo_factory
61+
```
62+
63+
#### Override hook
64+
65+
Requires explicit `:kind: override_hook` since it cannot be inferred from type.
66+
67+
```{eval-rst}
68+
.. autofixture:: spf_demo_fixtures.demo_override_hook
69+
:kind: override_hook
70+
```
71+
72+
---
73+
74+
### State badges
75+
76+
#### Autouse
77+
78+
```{eval-rst}
79+
.. autofixture:: spf_demo_fixtures.demo_autouse
80+
```
81+
82+
#### Deprecated
83+
84+
The `deprecated` badge is set via the `:deprecated:` RST option on `py:fixture`.
85+
86+
```{eval-rst}
87+
.. py:fixture:: demo_deprecated
88+
:deprecated: 1.0
89+
:replacement: demo_plain
90+
:return-type: str
91+
92+
Return a deprecated value. Use :fixture:`demo_plain` instead.
93+
```
94+
95+
---
96+
97+
### Combinations
98+
99+
#### Session + Factory
100+
101+
```{eval-rst}
102+
.. autofixture:: spf_demo_fixtures.demo_session_factory
103+
```
104+
105+
#### Session + Autouse
106+
107+
```{eval-rst}
108+
.. autofixture:: spf_demo_fixtures.demo_session_autouse
109+
```

docs/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ globals().update(conf)
5151
:hidden:
5252
5353
quickstart
54+
extensions/index
5455
project/index
5556
history
5657
```

0 commit comments

Comments
 (0)