You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
_Resolves #474_
# Problem
Issue #472 requires session-scoped fixtures.
Currently, we use `set_home`, `gitconfig`, and `hgconfig` to `monkeypatch.setenv` `$HOME`, pointing it to a temporary directory with user-specific configuration files. This ensures all subsequent `git` and `hg` commands automatically load these configurations.
However, [`monkeypatch.setenv`](https://docs.pytest.org/en/8.3.x/reference/reference.html#pytest.MonkeyPatch.setenv) doesn't work with function-scoped fixtures.
# Improvement
```
❯ hyperfine \
--warmup 3 \
--runs 10 \
--prepare 'git checkout master' \
--command-name 'libvcs 0.31.0' \
'py.test' \
--prepare 'git checkout pytest-config' \
--command-name 'with improved hg/git config fixtures' \
'py.test'
Benchmark 1: libvcs 0.31.0
Time (mean ± σ): 15.150 s ± 0.751 s [User: 16.650 s, System: 4.720 s]
Range (min … max): 14.235 s … 16.741 s 10 runs
Benchmark 2: with improved hg/git config fixtures
Time (mean ± σ): 15.014 s ± 0.307 s [User: 17.246 s, System: 4.865 s]
Range (min … max): 14.458 s … 15.642 s 10 runs
Summary
with improved hg/git config fixtures ran
1.01 ± 0.05 times faster than libvcs 0.31.0
```
# Changes
## pytest fixtures: Session-scoped `hgconfig` and `gitconfig`
These are now set by `set_hgconfig` and `set_gitconfig`, which set `HGRCPATH` and `GIT_CONFIG`, instead of overriding `HOME`.
Copy file name to clipboardExpand all lines: docs/pytest-plugin.md
+57-33
Original file line number
Diff line number
Diff line change
@@ -1,16 +1,14 @@
1
1
(pytest_plugin)=
2
2
3
-
# `pytest`plugin
3
+
# `pytest`Plugin
4
4
5
-
Create git, svn, and hg repos on the fly in [pytest].
5
+
With libvcs's pytest plugin for [pytest], you can easily create Git, SVN, and Mercurial repositories on the fly.
6
6
7
-
```{seealso}Using libvcs?
7
+
```{seealso}Are you using libvcs?
8
8
9
-
Do you want more flexibility? Correctness? Power? Defaults changed? [Connect with us] on the tracker, we want to know
10
-
your case, we won't stabilize APIs until we're sure everything is by the book.
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.
11
10
12
11
[connect with us]: https://github.com/vcs-python/libvcs/discussions
13
-
14
12
```
15
13
16
14
```{module} libvcs.pytest_plugin
@@ -21,66 +19,92 @@ your case, we won't stabilize APIs until we're sure everything is by the book.
21
19
22
20
## Usage
23
21
24
-
Install `libvcs`via the python package manager of your choosing, e.g.
22
+
Install `libvcs`using your preferred Python package manager:
25
23
26
24
```console
27
25
$ pip install libvcs
28
26
```
29
27
30
-
The pytest plugin will automatically be detected via pytest, and the fixtures will be added.
28
+
Pytest will automatically detect the plugin, and its fixtures will be available.
31
29
32
30
## Fixtures
33
31
34
-
`pytest-vcs` works through providing {ref}`pytest fixtures <pytest:fixtures-api>` - so read up on
35
-
those!
32
+
This pytest plugin works by providing {ref}`pytest fixtures <pytest:fixtures-api>`. 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.
36
33
37
-
The plugin's fixtures guarantee a fresh git repository every test.
To configure the above fixtures with `autouse=True`, add them to your `conftest.py` file or test file, depending on the desired scope.
62
+
63
+
_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.
64
+
65
+
### Setting a Temporary Home Directory
66
+
67
+
To set a temporary home directory, use the {func}`set_home` fixture with `autouse=True`:
68
+
69
+
```python
70
+
import pytest
71
+
72
+
@pytest.fixture(autouse=True)
73
+
defsetup(set_home: None):
74
+
pass
75
+
```
51
76
52
-
-`.gitconfig`, via {func}`gitconfig`:
53
-
-`.hgrc`, via {func}`hgconfig`:
77
+
### Setting a Default VCS Configuration
54
78
55
-
These are set to ensure you can correctly clone and create repositories without without extra
56
-
warnings.
79
+
#### Git
57
80
58
-
## Bootstrapping pytest in your `conftest.py`
81
+
Use the {func}`set_gitconfig` fixture with `autouse=True`:
59
82
60
-
The most common scenario is you will want to configure the above fixtures with `autouse`.
83
+
```python
84
+
import pytest
61
85
62
-
_Why doesn't the plugin automatically add them?_ It's part of being a decent pytest plugin and
63
-
python package: explicitness.
86
+
@pytest.fixture(autouse=True)
87
+
defsetup(set_gitconfig: None):
88
+
pass
89
+
```
64
90
65
-
(set_home)=
91
+
#### Mercurial
66
92
67
-
### Setting a temporary home directory
93
+
Use the {func}`set_hgconfig` fixture with `autouse=True`:
68
94
69
95
```python
70
96
import pytest
71
97
72
98
@pytest.fixture(autouse=True)
73
-
defsetup(
74
-
set_home: None,
75
-
):
99
+
defsetup(set_hgconfig: None):
76
100
pass
77
101
```
78
102
79
-
## See examples
103
+
## Examples
80
104
81
-
View libvcs's own [tests/](https://github.com/vcs-python/libvcs/tree/master/tests)
105
+
For usage examples, refer to libvcs's own [tests/](https://github.com/vcs-python/libvcs/tree/master/tests).
0 commit comments