Skip to content

Commit a488b5b

Browse files
authored
Create pytest_plugin (#409)
Extracts the suite's `conftest` into a pytest plugin. Removes the autouse on the fixtures to prevent automatic invocation when libvcs is installed.
2 parents 53be184 + eb8941d commit a488b5b

File tree

12 files changed

+563
-409
lines changed

12 files changed

+563
-409
lines changed

.coveragerc

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
11
[run]
2+
parallel = 1
3+
branch = 1
4+
25
omit =
3-
*/_*
4-
pkg/*
5-
*/log.py
6+
docs/conf.py
7+
*/_compat.py
68
*/conftest.py
79

810
[report]
11+
skip_covered = True
12+
show_missing = True
913
exclude_lines =
10-
pragma: no cover
11-
def __repr__
12-
raise NotImplementedError
13-
if __name__ == .__main__.:
14-
def parse_args
14+
\#\s*pragma: no cover
15+
^\s*raise NotImplementedError\b
16+
^\s*return NotImplemented\b
17+
^\s*assert False(,|$)
18+
^\s*assert_never\(
19+
20+
^\s*if TYPE_CHECKING:
21+
^\s*@overload( |$)

.github/workflows/tests.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,11 @@ jobs:
4343
poetry run python -V
4444
4545
- name: Test with pytest
46-
run: poetry run py.test --cov=./ --cov-report=xml
47-
46+
run: poetry run py.test --cov=./ --cov-append --cov-report=xml
47+
env:
48+
COV_CORE_SOURCE: .
49+
COV_CORE_CONFIG: .coveragerc
50+
COV_CORE_DATAFILE: .coverage.eager
4851
- uses: codecov/codecov-action@v3
4952
with:
5053
token: ${{ secrets.CODECOV_TOKEN }}

docs/conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@
161161
intersphinx_mapping = {
162162
"py": ("https://docs.python.org/3", None),
163163
"pip": ("https://pip.pypa.io/en/latest/", None),
164+
"pytest": ("https://docs.pytest.org/en/stable/", None),
164165
"vcspull": ("https://vcspull.git-pull.com/", None),
165166
"gp-libs": ("https://gp-libs.git-pull.com/", None),
166167
}

docs/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ quickstart
1212
url/index
1313
cmd/index
1414
sync/index
15+
pytest-plugin
1516
```
1617

1718
```{toctree}

docs/pytest-plugin.md

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
(pytest_plugin)=
2+
3+
# `pytest` plugin
4+
5+
Create git, svn, and hg repos on the fly in [pytest].
6+
7+
```{seealso} Using libvcs?
8+
9+
Do you want more flexbility? 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.
11+
12+
[connect with us]: https://github.com/vcs-python/libvcs/discussions
13+
14+
```
15+
16+
```{module} libvcs.pytest_plugin
17+
18+
```
19+
20+
[pytest]: https://docs.pytest.org/
21+
22+
## Usage
23+
24+
Install `libvcs` via the python package manager of your choosing, e.g.
25+
26+
```console
27+
$ pip install libvcs
28+
```
29+
30+
The pytest plugin will automatically be detected via pytest, and the fixtures will be added.
31+
32+
## Fixtures
33+
34+
`pytest-vcs` works through providing {ref}`pytest fixtures <pytest:fixtures-api>` - so read up on
35+
those!
36+
37+
The plugin's fixtures guarantee a fresh git repository very test.
38+
39+
(recommended-fixtures)=
40+
41+
## Recommended fixtures
42+
43+
These are fixtures are automatically used when the plugin is enabled and `pytest` is ran.
44+
45+
- Creating temporary, test directories for:
46+
- `/home/` ({func}`home_path`)
47+
- `/home/${user}` ({func}`user_path`)
48+
- Setting your home directory
49+
- Patch `$HOME` to point to {func}`user_path` ({func}`set_home`)
50+
- Set default configuration
51+
52+
- `.gitconfig`, via {func}`gitconfig`:
53+
- `.hgrc`, via {func}`hgconfig`:
54+
55+
These are set to ensure you can correctly clone and create repositories withou. without extra
56+
warnings.
57+
58+
## Bootstrapping pytest in your `conftest.py`
59+
60+
The most common scenario is you will want to configure the above fixtures with `autouse`.
61+
62+
_Why doesn't the plugin automatically add them?_ It's part of being a decent pytest plugin and
63+
python package: explicitness.
64+
65+
(set_home)=
66+
67+
### Setting a temporary home directory
68+
69+
```python
70+
import pytest
71+
72+
@pytest.fixture(autouse=True)
73+
def setup(
74+
set_home: None,
75+
):
76+
pass
77+
```
78+
79+
## See examples
80+
81+
View libvcs's own [tests/](https://github.com/vcs-python/libvcs/tree/master/tests)
82+
83+
## API reference
84+
85+
```{eval-rst}
86+
.. automodule:: libvcs.pytest_plugin
87+
:members:
88+
:inherited-members:
89+
:private-members:
90+
:show-inheritance:
91+
:member-order: bysource
92+
`
93+
```

pyproject.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ classifiers = [
2626
"Development Status :: 4 - Beta",
2727
"License :: OSI Approved :: MIT License",
2828
"Environment :: Console",
29+
"Framework :: Pytest",
2930
"Intended Audience :: Developers",
3031
"Operating System :: POSIX",
3132
"Operating System :: MacOS :: MacOS X",
@@ -128,6 +129,9 @@ lint = [
128129
"types-docutils",
129130
]
130131

132+
[tool.poetry.plugins.pytest11]
133+
libvcs = "libvcs.pytest_plugin"
134+
131135
[tool.mypy]
132136
strict = true
133137

0 commit comments

Comments
 (0)