Skip to content

Commit ae3c53f

Browse files
authored
docs: Adopt doc-pytest-plugin for pytest plugin page (#520)
Replaces the hand-authored pytest plugin page with the shared `doc-pytest-plugin` directive from `sphinx-autodoc-pytest-fixtures`. The generated page provides a consistent install block, `pytest11` autodiscovery note, fixture summary table, and full fixture reference — maintained automatically as fixtures change. - **docs/api/pytest-plugin.md** — rewritten around `doc-pytest-plugin` with project-specific prose in the body - **docs/conf.py** — enables `sphinx_autodoc_pytest_fixtures` extension and adds `pytest-plugin` to the API toctree - **pyproject.toml** — bumps `gp-sphinx` and `sphinx-autodoc-pytest-fixtures` to `0.0.1a2`
2 parents 75069c9 + 7727b7a commit ae3c53f

File tree

6 files changed

+65
-146
lines changed

6 files changed

+65
-146
lines changed

docs/api/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ One call to fetch or create a working copy.
3737
:::
3838

3939
:::{grid-item-card} pytest Plugin
40-
:link: api/pytest-plugin
40+
:link: /api/pytest-plugin
4141
:link-type: doc
4242
Session-scoped fixtures for Git, SVN, and Mercurial
4343
repositories. Drop-in test isolation.

docs/api/pytest-plugin.md

Lines changed: 25 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -2,146 +2,42 @@
22

33
# `pytest` Plugin
44

5-
With libvcs's pytest plugin for [pytest], you can easily create Git, SVN, and Mercurial repositories on the fly.
5+
:::{doc-pytest-plugin} libvcs.pytest_plugin
6+
:project: libvcs
7+
:package: libvcs
8+
:summary: libvcs ships a pytest plugin for creating isolated Git, Mercurial, and Subversion repositories during tests.
9+
:tests-url: https://github.com/vcs-python/libvcs/tree/master/tests
610

7-
```{seealso} Are you using libvcs?
11+
Use these fixtures when your tests need disposable repositories, config files,
12+
and home-directory setup without repeating bootstrap code in every suite.
813

9-
Looking for more flexibility, correctness, or power? Need different defaults? [Connect with us] on GitHub. We'd love to hear about your use case—APIs won't be stabilized until we're confident everything meets expectations.
14+
## Recommended fixtures
1015

11-
[connect with us]: https://github.com/vcs-python/libvcs/discussions
12-
```
13-
14-
[pytest]: https://docs.pytest.org/
15-
16-
## Usage
17-
18-
Install `libvcs` using your preferred Python package manager:
19-
20-
```console
21-
$ pip install libvcs
22-
```
23-
24-
Pytest will automatically detect the plugin, and its fixtures will be available.
25-
26-
## Fixtures
27-
28-
This pytest plugin works by providing [pytest fixtures](https://docs.pytest.org/en/stable/how-to/fixtures.html). The plugin's fixtures ensure that a fresh Git, Subversion, or Mercurial repository is available for each test. It utilizes [session-scoped fixtures] to cache initial repositories, improving performance across tests.
29-
30-
[session-scoped fixtures]: https://docs.pytest.org/en/8.3.x/how-to/fixtures.html#fixture-scopes
31-
32-
(recommended-fixtures)=
33-
34-
## Recommended Fixtures
35-
36-
When the plugin is enabled and `pytest` is run, these overridable fixtures are automatically used:
16+
These fixtures are the usual starting point when enabling the plugin:
3717

38-
- Create temporary test directories for:
39-
- `/home/` ({func}`home_path`)
40-
- `/home/${user}` ({func}`user_path`)
41-
- Set the home directory:
42-
- Patch `$HOME` to point to {func}`user_path` using ({func}`set_home`)
43-
- Create configuration files:
44-
- `.gitconfig` via {func}`gitconfig`
45-
- `.hgrc` via {func}`hgconfig`
46-
- Set default VCS configurations:
47-
- Use {func}`hgconfig` for [`HGRCPATH`] via {func}`set_hgconfig`
48-
- Use {func}`gitconfig` for [`GIT_CONFIG`] via {func}`set_gitconfig`
49-
- Set default commit names and emails:
50-
- Name: {func}`vcs_name`
51-
- Email: {func}`vcs_email`
52-
- User (e.g. _`user <email@tld>`_): {func}`vcs_user`
53-
- For git only: {func}`git_commit_envvars`
18+
- {fixture}`set_home` patches `$HOME` to point at {fixture}`user_path`.
19+
- {fixture}`set_gitconfig` and {fixture}`set_hgconfig` apply stable VCS
20+
configuration.
21+
- {fixture}`vcs_name`, {fixture}`vcs_email`, and {fixture}`vcs_user` let you
22+
override commit identity defaults.
23+
- {fixture}`git_commit_envvars` helps when Git ignores `GIT_CONFIG` in a
24+
subprocess-heavy test.
5425

55-
These ensure that repositories can be cloned and created without unnecessary warnings.
26+
## Bootstrapping in `conftest.py`
5627

57-
[`HGRCPATH`]: https://www.mercurial-scm.org/doc/hg.1.html#:~:text=UNIX%2Dlike%20environments.-,HGRCPATH,-If%20not%20set
58-
[`GIT_CONFIG`]: https://git-scm.com/docs/git-config#Documentation/git-config.txt-GITCONFIG
59-
60-
## Bootstrapping pytest in `conftest.py`
61-
62-
To configure the above fixtures with `autouse=True`, add them to your `conftest.py` file or test file, depending on the desired scope.
63-
64-
_Why aren't these fixtures added automatically by the plugin?_ This design choice promotes explicitness, adhering to best practices for pytest plugins and Python packages.
65-
66-
### Setting a Temporary Home Directory
67-
68-
To set a temporary home directory, use the {func}`set_home` fixture with `autouse=True`:
28+
Keep autouse setup explicit in your own `conftest.py` instead of having the
29+
plugin force global side effects.
6930

7031
```python
7132
import pytest
7233

73-
@pytest.fixture(autouse=True)
74-
def setup(set_home: None):
75-
pass
76-
```
77-
78-
### VCS Configuration
79-
80-
#### Git
81-
82-
You can override the default author used in {func}`git_remote_repo` and other
83-
fixtures via {func}`vcs_name`, {func}`vcs_email`, and {func}`vcs_user`:
84-
85-
```
86-
@pytest.fixture(scope="session")
87-
def vcs_name() -> str:
88-
return "My custom name"
89-
```
90-
91-
Use the {func}`set_gitconfig` fixture with `autouse=True`:
92-
93-
```python
94-
import pytest
9534

9635
@pytest.fixture(autouse=True)
97-
def setup(set_gitconfig: None):
36+
def setup(
37+
set_home: None,
38+
set_gitconfig: None,
39+
set_hgconfig: None,
40+
) -> None:
9841
pass
9942
```
100-
101-
Sometimes, `set_getconfig` via `GIT_CONFIG` doesn't apply as expected. For those
102-
cases, you can use {func}`git_commit_envvars`:
103-
104-
```python
105-
import pytest
106-
107-
@pytest.fixture
108-
def my_git_repo(
109-
create_git_remote_repo: CreateRepoPytestFixtureFn,
110-
gitconfig: pathlib.Path,
111-
git_commit_envvars: "_ENV",
112-
) -> pathlib.Path:
113-
"""Copy the session-scoped Git repository to a temporary directory."""
114-
repo_path = create_git_remote_repo()
115-
git_remote_repo_single_commit_post_init(
116-
remote_repo_path=repo_path,
117-
env=git_commit_envvars,
118-
)
119-
return repo_path
120-
```
121-
122-
#### Mercurial
123-
124-
Use the {func}`set_hgconfig` fixture with `autouse=True`:
125-
126-
```python
127-
import pytest
128-
129-
@pytest.fixture(autouse=True)
130-
def setup(set_hgconfig: None):
131-
pass
132-
```
133-
134-
## Examples
135-
136-
For usage examples, refer to libvcs's own [tests/](https://github.com/vcs-python/libvcs/tree/master/tests).
137-
138-
## API Reference
139-
140-
```{eval-rst}
141-
.. automodule:: libvcs.pytest_plugin
142-
:members:
143-
:inherited-members:
144-
:private-members:
145-
:show-inheritance:
146-
:member-order: bysource
147-
```
43+
:::

docs/conf.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@
3030
source_branch="master",
3131
light_logo="img/libvcs.svg",
3232
dark_logo="img/libvcs-dark.svg",
33-
extra_extensions=["sphinx.ext.todo"],
33+
extra_extensions=[
34+
"sphinx.ext.todo",
35+
"sphinx_autodoc_pytest_fixtures",
36+
],
3437
intersphinx_mapping={
3538
"py": ("https://docs.python.org/3", None),
3639
"pip": ("https://pip.pypa.io/en/latest/", None),

docs/index.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Clone and update local repositories.
3434
:::
3535

3636
:::{grid-item-card} pytest Plugin
37-
:link: api/pytest-plugin
37+
:link: /api/pytest-plugin
3838
:link-type: doc
3939
Fixtures for isolated VCS test repos.
4040
:::
@@ -88,7 +88,7 @@ updates a local checkout in one call.
8888

8989
## Testing
9090

91-
libvcs ships a [pytest plugin](api/pytest-plugin.md) with
91+
libvcs ships a [pytest plugin](/api/pytest-plugin/) with
9292
session-scoped fixtures for Git, SVN, and Mercurial repositories:
9393

9494
```python

pyproject.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ Changes = "https://github.com/vcs-python/libvcs/blob/master/CHANGES"
6464
[dependency-groups]
6565
dev = [
6666
# Docs
67-
"gp-sphinx==0.0.1a1",
67+
"gp-sphinx==0.0.1a2",
68+
"sphinx-autodoc-pytest-fixtures==0.0.1a2",
6869
"gp-libs",
6970
"sphinx-autobuild",
7071
# Testing
@@ -83,7 +84,8 @@ dev = [
8384
]
8485

8586
docs = [
86-
"gp-sphinx==0.0.1a1",
87+
"gp-sphinx==0.0.1a2",
88+
"sphinx-autodoc-pytest-fixtures==0.0.1a2",
8789
"gp-libs",
8890
"sphinx-autobuild",
8991
]

uv.lock

Lines changed: 29 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)