File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Load diff This file was deleted.
Original file line number Diff line number Diff line change @@ -110,8 +110,7 @@ which is always imported.
110110
111111``` py
112112import 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
115114if 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
127126This 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
129128extraneous 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.
Original file line number Diff line number Diff line change @@ -48,9 +48,6 @@ Funding = 'https://github.com/sponsors/samuelcolvin'
4848Source = ' https://github.com/samuelcolvin/python-devtools'
4949Changelog = ' https://github.com/samuelcolvin/python-devtools/releases'
5050
51- [project .entry-points .pytest11 ]
52- devtools = ' devtools.pytest_plugin'
53-
5451[tool .uv ]
5552default-groups = [" dev" , " docs" ]
5653
@@ -60,7 +57,6 @@ module-root = ""
6057[dependency-groups ]
6158dev = [
6259 " basedpyright>=1.40.2" ,
63- " black" ,
6460 " coverage[toml]" ,
6561 " pytest>=8" ,
6662 " pytest-mock" ,
Original file line number Diff line number Diff line change 22
33import pytest
44
5- pytest_plugins = ['pytester' ]
6-
75
86def pytest_sessionstart (session : pytest .Session ) -> None :
97 os .environ .pop ('PY_DEVTOOLS_HIGHLIGHT' , None )
You can’t perform that action at this time.
0 commit comments