Run notebook code written in Python.
(item)
| 1170 | |
| 1171 | |
| 1172 | def pytest_runtest_call(item): |
| 1173 | """Run notebook code written in Python.""" |
| 1174 | if "nbexec" in getattr(item, "fixturenames", ()): |
| 1175 | nbexec = item.funcargs["nbexec"] |
| 1176 | code = inspect.getsource(getattr(item.module, item.name.split("[")[0])) |
| 1177 | code = code.splitlines() |
| 1178 | ci = 0 |
| 1179 | for ci, c in enumerate(code): |
| 1180 | if c.startswith(" "): # actual content |
| 1181 | break |
| 1182 | code = "\n".join(code[ci:]) |
| 1183 | |
| 1184 | def run(nbexec=nbexec, code=code): |
| 1185 | nbexec(code) |
| 1186 | |
| 1187 | item.runtest = run |
| 1188 | return |
| 1189 | |
| 1190 | |
| 1191 | @pytest.fixture( |