StrictVerifier¶
StrictVerifier
¶
Manages plugin lifecycle, sandbox context, and assertion verification.
Do NOT instantiate directly. Use tripwire's pytest integration:
# In your test:
tripwire.http.mock_response("GET", "/api", json={"ok": True})
with tripwire:
response = requests.get("/api")
tripwire.http.assert_request("GET", "/api", status=200)
Direct instantiation bypasses forced assertion checking and will silently produce tests that pass without verifying anything.
To access the verifier in a fixture or helper: verifier = tripwire.current_verifier()
Source code in src/tripwire/_verifier.py
mock
¶
Create an import-site mock. Path format: 'module:attr'.
Lazily creates MockPlugin if not already registered.
Source code in src/tripwire/_verifier.py
spy
¶
Create an import-site spy. Path format: 'module:attr'.
Lazily creates MockPlugin if not already registered.
Source code in src/tripwire/_verifier.py
assert_interaction
¶
Assert the next interaction matches source and expected fields.
Completeness enforcement: after matching by source_id, the interaction's plugin.assertable_fields() is called. Any field in the returned set that is absent from **expected raises MissingAssertionFieldsError immediately, before the field-value match check.
Source code in src/tripwire/_verifier.py
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 | |
in_any_order
¶
Context manager: assertions within block matched in any order.
IMPORTANT: in_any_order() relaxes ordering globally across ALL plugins. It is not possible to relax ordering for only one plugin type. Any assert_interaction() call within this block will match any unasserted interaction regardless of which plugin (mock or HTTP) recorded it.
Source code in src/tripwire/_verifier.py
verify_all
¶
Run Enforcement 2 and 3. Called at teardown.
Only interactions with enforce=True are checked. Interactions recorded during individual mock activation (enforce=False) are not required to be asserted.
Source code in src/tripwire/_verifier.py
SandboxContext
¶
Activates all plugins and mocks. Supports both sync (with) and async (async with).