inline_snapshot.extra
¶
The following functions are build on top of inline-snapshot and could also be implemented in an extra library.
They are part of inline-snapshot because they are general useful and do not depend on other libraries.
prints(*, stdout='', stderr='')
¶
Uses contextlib.redirect_stderr/stdout
to capture the output and
compare it with the snapshots. dirty_equals.IsStr
can be used to ignore
the output if needed.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
stdout
|
Snapshot[str]
|
snapshot which is compared to the recorded output |
''
|
stderr
|
Snapshot[str]
|
snapshot which is compared to the recorded error output |
''
|
Source code in src/inline_snapshot/extra.py
raises(exception)
¶
Check that an exception is raised.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
exception
|
Snapshot[str]
|
snapshot which is compared with |
required |
Source code in src/inline_snapshot/extra.py
warns(expected_warnings, /, include_line=False, include_file=False)
¶
Captures warnings with warnings.catch_warnings
and compares them against expected warnings.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
expected_warnings
|
Snapshot[List[Warning]]
|
Snapshot containing a list of expected warnings. |
required |
include_line
|
bool
|
If |
False
|
include_file
|
bool
|
If |
False
|
The format of the expected warning:
(filename, linenumber, message)
if bothinclude_line
andinclude_file
areTrue
.(linenumber, message)
if onlyinclude_line
isTrue
.(filename, message)
if onlyinclude_file
isTrue
.- A string
message
if both areFalse
.