Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit bac8294

Browse filesBrowse files
committed
docs(pytest plugin) Document new fixtures
1 parent d35b501 commit bac8294
Copy full SHA for bac8294

File tree

Expand file treeCollapse file tree

1 file changed

+37
-2
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+37
-2
lines changed

‎docs/pytest-plugin.md

Copy file name to clipboardExpand all lines: docs/pytest-plugin.md
+37-2Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ This pytest plugin works by providing {ref}`pytest fixtures <pytest:fixtures-api
3737

3838
## Recommended Fixtures
3939

40-
When the plugin is enabled and `pytest` is run, these fixtures are automatically used:
40+
When the plugin is enabled and `pytest` is run, these overridable fixtures are automatically used:
4141

4242
- Create temporary test directories for:
4343
- `/home/` ({func}`home_path`)
@@ -50,6 +50,11 @@ When the plugin is enabled and `pytest` is run, these fixtures are automatically
5050
- Set default VCS configurations:
5151
- Use {func}`hgconfig` for [`HGRCPATH`] via {func}`set_hgconfig`
5252
- Use {func}`gitconfig` for [`GIT_CONFIG`] via {func}`set_gitconfig`
53+
- Set default commit names and emails:
54+
- Name: {func}`vcs_name`
55+
- Email: {func}`vcs_email`
56+
- User (e.g. _`user <email@tld>`_): {func}`vcs_user`
57+
- For git only: {func}`git_commit_envvars`
5358

5459
These ensure that repositories can be cloned and created without unnecessary warnings.
5560

@@ -74,10 +79,19 @@ def setup(set_home: None):
7479
pass
7580
```
7681

77-
### Setting a Default VCS Configuration
82+
### VCS Configuration
7883

7984
#### Git
8085

86+
You can override the default author used in {func}`git_remote_repo` and other
87+
fixtures via {func}`vcs_name`, {func}`vcs_email`, and {func}`vcs_user`:
88+
89+
```
90+
@pytest.fixture(scope="session")
91+
def vcs_name() -> str:
92+
return "My custom name"
93+
```
94+
8195
Use the {func}`set_gitconfig` fixture with `autouse=True`:
8296

8397
```python
@@ -88,6 +102,27 @@ def setup(set_gitconfig: None):
88102
pass
89103
```
90104

105+
Sometimes, `set_getconfig` via `GIT_CONFIG` doesn't apply as expected. For those
106+
cases, you can use {func}`git_commit_envvars`:
107+
108+
```python
109+
import pytest
110+
111+
@pytest.fixture
112+
def my_git_repo(
113+
create_git_remote_repo: CreateRepoPytestFixtureFn,
114+
gitconfig: pathlib.Path,
115+
git_commit_envvars: "_ENV",
116+
) -> pathlib.Path:
117+
"""Copy the session-scoped Git repository to a temporary directory."""
118+
repo_path = create_git_remote_repo()
119+
git_remote_repo_single_commit_post_init(
120+
remote_repo_path=repo_path,
121+
env=git_commit_envvars,
122+
)
123+
return repo_path
124+
```
125+
91126
#### Mercurial
92127

93128
Use the {func}`set_hgconfig` fixture with `autouse=True`:

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.