.md →
LiveEdit API#
LiveEdit takes one call — LiveEdit.inspect_run(fn, *args, **kwargs) — and lays the
run out next to its source: the setup values, a row per loop pass including nested child
loops, and the value that came back. Click a numeric column header to chart that column
across passes. LiveEdit.from_pytest("tests/test_foo.py::test_bar") does the same for a
test body, with a failing assert rendered on the offending line instead of raised, so
a broken test becomes something you read rather than something you re-run with print
statements.
See also: AsyncFlow for the same idea applied to an async run, ApiDoc for rendering a function's signature and docstring, and Matrix for editing the numbers you feed in by hand.
Bases: AnyWidget
Read-only function trace widget for inspecting one Python run.
LiveEdit.inspect_run(fn, *args, **kwargs) is the primary constructor for
v1. The widget stores the original Python args privately and only syncs
repr-based trace data to the browser, which keeps future editable code
updates possible without serializing arbitrary Python objects.
Source code in wigglystuff/live_edit.py
from_pytest
classmethod
#
from_pytest(nodeid: str, *args: Any, float_precision: int | None = None, visible_columns: list[str] | None = None, **kwargs: Any) -> 'LiveEdit'
Trace one pytest test's body with LiveEdit.
nodeid is a pytest node id like "tests/test_foo.py::test_bar"
(the same string you would pass on the command line). LiveEdit then
traces the test function body exactly as inspect_run would.
Calls into other functions stay opaque (you see a call's return value,
not its internals). A failing assert is rendered on the offending
source line rather than raised.
Arguments come from one of two places:
- Nothing passed (default): pytest resolves the test's fixtures,
parametrization, and
conftest.pyand the test runs once. If the node id matches several tests (e.g. a parametrized test given by its bare name), no test is traced and an error asks you to pass a specific...::test_bar[case]id or supply arguments yourself. - Args/keyword args passed (e.g.
from_pytest(nodeid, x=3)): those values are used directly and fixtures are bypassed entirely. This is the escape hatch for parametrized tests or tests whose fixtures are too heavy to spin up just to watch the logic.
Only module-level def test_* functions are supported: class-based
tests (TestClass::test_x) and async def tests raise a clear
error. Tests wrapped in a behaviour-changing decorator (e.g.
@mock.patch(...)) aren't traced either, because the trace runs a
re-exec'd copy of the source; use the fixture forms (monkeypatch,
mocker) — which are resolved normally — or pass args manually.
Note: pytest imports each test module once per process, so editing the
test file and calling from_pytest again in the same kernel may reuse
the stale module.
Source code in wigglystuff/live_edit.py
1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 | |
Synced traitlets#
| Traitlet | Type | Notes |
|---|---|---|
code |
str |
Source code for the traced function. This is the future live-edit source of truth. |
trace |
dict |
Structured setup values, loop passes, nested child loops, and returned value. |
annotations |
dict |
Static line/token metadata used by the browser for hover linking. |
error |
dict or None |
Parse, runtime, or argument mismatch error payload; None when the run succeeds. |
editable |
bool |
Reserved for the future browser editor mode. Defaults to False. |
theme |
str |
"auto", "light", or "dark". |
width |
int |
Widget width in pixels. |
height |
int |
Maximum widget height in pixels. |