Skip to content

Commit 4096b67

Browse files
samuelcolvinclaude
andauthored
Remove the pytest plugin, recommend inline-snapshot instead (#174)
Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
1 parent d8141b5 commit 4096b67

6 files changed

Lines changed: 25 additions & 610 deletions

File tree

‎devtools/pytest_plugin.py‎

Lines changed: 0 additions & 305 deletions
This file was deleted.

‎docs/usage.md‎

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,7 @@ which is always imported.
110110

111111
```py
112112
import sys
113-
# we don't install here for pytest as it breaks pytest, it is
114-
# installed later by a pytest fixture
113+
# importing devtools this early breaks pytest, so skip it there
115114
if not sys.argv[0].endswith('pytest'):
116115
import builtins
117116
try:
@@ -127,3 +126,25 @@ The `ImportError` exception is important since you'll want python to run fine ev
127126
This approach has another advantage: if you forget to remove `debug(...)` calls from your code, CI
128127
(which won't have devtools installed) should fail both on execution and linting, meaning you don't end up with
129128
extraneous debug calls in production code.
129+
130+
## Snapshot testing
131+
132+
Earlier versions of *devtools* shipped a pytest plugin with an `insert_assert()` function which rewrote test files
133+
to turn a value into an `assert` statement. That plugin has been removed, use
134+
[inline-snapshot](https://15r10nk.github.io/inline-snapshot/0.36/) instead, which does the same job better and is
135+
actively maintained.
136+
137+
```py
138+
from inline_snapshot import snapshot
139+
140+
141+
def something():
142+
return 1548 * 18489
143+
144+
145+
def test_something():
146+
assert something() == snapshot()
147+
```
148+
149+
Running `pytest` with `--inline-snapshot=create` fills in `snapshot()` with the current value, and
150+
`--inline-snapshot=fix` updates snapshots whose value has changed, after you've checked the new value is right.

‎pyproject.toml‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,6 @@ Funding = 'https://github.com/sponsors/samuelcolvin'
4848
Source = 'https://github.com/samuelcolvin/python-devtools'
4949
Changelog = 'https://github.com/samuelcolvin/python-devtools/releases'
5050

51-
[project.entry-points.pytest11]
52-
devtools = 'devtools.pytest_plugin'
53-
5451
[tool.uv]
5552
default-groups = ["dev", "docs"]
5653

@@ -60,7 +57,6 @@ module-root = ""
6057
[dependency-groups]
6158
dev = [
6259
"basedpyright>=1.40.2",
63-
"black",
6460
"coverage[toml]",
6561
"pytest>=8",
6662
"pytest-mock",

‎tests/conftest.py‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
import pytest
44

5-
pytest_plugins = ['pytester']
6-
75

86
def pytest_sessionstart(session: pytest.Session) -> None:
97
os.environ.pop('PY_DEVTOOLS_HIGHLIGHT', None)

0 commit comments

Comments
 (0)