Skip to content

Commit

Permalink
update logging
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisjsewell committed Aug 11, 2019
1 parent ddfc560 commit 77671f4
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 46 deletions.
39 changes: 20 additions & 19 deletions docs/source/user_guide/tutorial_intro.ipynb
Expand Up @@ -312,7 +312,7 @@
"\u001b[1m============================= test session starts ==============================\u001b[0m\n",
"platform darwin -- Python 3.6.7, pytest-5.0.1, py-1.8.0, pluggy-0.12.0 -- //anaconda/envs/pytest_nb/bin/python\n",
"cachedir: .pytest_cache\n",
"rootdir: /private/var/folders/dm/b2qnkb_n3r72slmpxlfmcjvm00lbnd/T/tmp35y176h3, inifile: pytest.ini\n",
"rootdir: /private/var/folders/dm/b2qnkb_n3r72slmpxlfmcjvm00lbnd/T/tmpug63o49o, inifile: pytest.ini\n",
"plugins: cov-2.7.1, datadir-1.3.0, regressions-1.0.5, notebook-0.2.0\n",
"\u001b[1mcollecting ... \u001b[0mcollected 1 item\n",
"\n",
Expand Down Expand Up @@ -341,7 +341,7 @@
"\u001b[1m\u001b[31mE \u001b[0m\u001b[0m\n",
"\n",
"\u001b[1m\u001b[31mtest_ipycell.py\u001b[0m:8: NBRegressionError\n",
"\u001b[31m\u001b[1m===================== 1 failed, 1 warnings in 1.99 seconds =====================\u001b[0m\n"
"\u001b[31m\u001b[1m===================== 1 failed, 1 warnings in 2.34 seconds =====================\u001b[0m\n"
]
}
],
Expand Down Expand Up @@ -398,7 +398,7 @@
"\u001b[1m============================= test session starts ==============================\u001b[0m\n",
"platform darwin -- Python 3.6.7, pytest-5.0.1, py-1.8.0, pluggy-0.12.0 -- //anaconda/envs/pytest_nb/bin/python\n",
"cachedir: .pytest_cache\n",
"rootdir: /private/var/folders/dm/b2qnkb_n3r72slmpxlfmcjvm00lbnd/T/tmpklix063p\n",
"rootdir: /private/var/folders/dm/b2qnkb_n3r72slmpxlfmcjvm00lbnd/T/tmp37lbyeao\n",
"plugins: cov-2.7.1, datadir-1.3.0, regressions-1.0.5, notebook-0.2.0\n",
"\u001b[1mcollecting ... \u001b[0mcollected 2 items\n",
"\n",
Expand All @@ -421,7 +421,7 @@
"\u001b[32m+\u001b[m\u001b[32mhallo2\u001b[m\n",
"\n",
"\u001b[0m\n",
"\u001b[31m\u001b[1m================ 1 failed, 1 passed, 1 warnings in 3.16 seconds ================\u001b[0m\n"
"\u001b[31m\u001b[1m================ 1 failed, 1 passed, 1 warnings in 2.91 seconds ================\u001b[0m\n"
]
}
],
Expand All @@ -446,7 +446,7 @@
"\u001b[1m============================= test session starts ==============================\u001b[0m\n",
"platform darwin -- Python 3.6.7, pytest-5.0.1, py-1.8.0, pluggy-0.12.0 -- //anaconda/envs/pytest_nb/bin/python\n",
"cachedir: .pytest_cache\n",
"rootdir: /private/var/folders/dm/b2qnkb_n3r72slmpxlfmcjvm00lbnd/T/tmpfeeqhq5k, inifile: pytest.ini\n",
"rootdir: /private/var/folders/dm/b2qnkb_n3r72slmpxlfmcjvm00lbnd/T/tmp45enuz3y, inifile: pytest.ini\n",
"plugins: cov-2.7.1, datadir-1.3.0, regressions-1.0.5, notebook-0.2.0\n",
"\u001b[1mcollecting ... \u001b[0mcollected 2 items\n",
"\n",
Expand All @@ -469,7 +469,7 @@
"\u001b[32m+\u001b[m\u001b[32mhallo2\u001b[m\n",
"\n",
"\u001b[0m\n",
"\u001b[31m\u001b[1m================ 1 failed, 1 passed, 1 warnings in 3.07 seconds ================\u001b[0m\n"
"\u001b[31m\u001b[1m================ 1 failed, 1 passed, 1 warnings in 2.93 seconds ================\u001b[0m\n"
]
}
],
Expand Down Expand Up @@ -506,13 +506,13 @@
"\u001b[1m============================= test session starts ==============================\u001b[0m\n",
"platform darwin -- Python 3.6.7, pytest-5.0.1, py-1.8.0, pluggy-0.12.0 -- //anaconda/envs/pytest_nb/bin/python\n",
"cachedir: .pytest_cache\n",
"rootdir: /private/var/folders/dm/b2qnkb_n3r72slmpxlfmcjvm00lbnd/T/tmpdnydaqke, inifile: pytest.ini\n",
"rootdir: /private/var/folders/dm/b2qnkb_n3r72slmpxlfmcjvm00lbnd/T/tmpph9rg8r8, inifile: pytest.ini\n",
"plugins: cov-2.7.1, datadir-1.3.0, regressions-1.0.5, notebook-0.2.0\n",
"\u001b[1mcollecting ... \u001b[0mcollected 1 item\n",
"\n",
"test_notebook1.ipynb::nbregression(test_notebook1) \u001b[32mPASSED\u001b[0m\u001b[36m [100%]\u001b[0m\n",
"\n",
"\u001b[33m\u001b[1m===================== 1 passed, 1 warnings in 1.82 seconds =====================\u001b[0m\n"
"\u001b[33m\u001b[1m===================== 1 passed, 1 warnings in 2.00 seconds =====================\u001b[0m\n"
]
}
],
Expand Down Expand Up @@ -557,18 +557,19 @@
"\u001b[1m============================= test session starts ==============================\u001b[0m\n",
"platform darwin -- Python 3.6.7, pytest-5.0.1, py-1.8.0, pluggy-0.12.0 -- //anaconda/envs/pytest_nb/bin/python\n",
"cachedir: .pytest_cache\n",
"rootdir: /private/var/folders/dm/b2qnkb_n3r72slmpxlfmcjvm00lbnd/T/tmp9z9j0ri8\n",
"rootdir: /private/var/folders/dm/b2qnkb_n3r72slmpxlfmcjvm00lbnd/T/tmpmoeqvr4t\n",
"plugins: cov-2.7.1, datadir-1.3.0, regressions-1.0.5, notebook-0.2.0\n",
"\u001b[1mcollecting ... \u001b[0mcollected 1 item\n",
"\n",
"test_notebook1.ipynb::nbregression(test_notebook1) \n",
"\u001b[1m-------------------------------- live log call ---------------------------------\u001b[0m\n",
"\u001b[32mINFO \u001b[0m pytest_notebook.execution:execution.py:19 About to execute notebook with 3 cells\n",
"\u001b[32mINFO \u001b[0m traitlets:execute.py:404 Executing notebook with kernel: python3\n",
"\u001b[32mINFO \u001b[0m pytest_notebook.execution:execution.py:27 Executing cell 1\n",
"\u001b[32mINFO \u001b[0m pytest_notebook.execution:execution.py:27 Executing cell 2\n",
"\u001b[32mINFO \u001b[0m pytest_notebook.execution:execution.py:25 Executing cell 1\n",
"\u001b[32mINFO \u001b[0m pytest_notebook.execution:execution.py:25 Executing cell 2\n",
"\u001b[32mPASSED\u001b[0m\u001b[36m [100%]\u001b[0m\n",
"\n",
"\u001b[33m\u001b[1m===================== 1 passed, 1 warnings in 2.16 seconds =====================\u001b[0m\n"
"\u001b[33m\u001b[1m===================== 1 passed, 1 warnings in 1.80 seconds =====================\u001b[0m\n"
]
}
],
Expand Down Expand Up @@ -616,7 +617,7 @@
"\u001b[1m============================= test session starts ==============================\u001b[0m\n",
"platform darwin -- Python 3.6.7, pytest-5.0.1, py-1.8.0, pluggy-0.12.0 -- //anaconda/envs/pytest_nb/bin/python\n",
"cachedir: .pytest_cache\n",
"rootdir: /private/var/folders/dm/b2qnkb_n3r72slmpxlfmcjvm00lbnd/T/tmp11t_tnui, inifile: pytest.ini\n",
"rootdir: /private/var/folders/dm/b2qnkb_n3r72slmpxlfmcjvm00lbnd/T/tmp8tzajwom, inifile: pytest.ini\n",
"plugins: cov-2.7.1, datadir-1.3.0, regressions-1.0.5, notebook-0.2.0\n",
"\u001b[1mcollecting ... \u001b[0mcollected 2 items\n",
"\n",
Expand All @@ -626,7 +627,7 @@
"=================================== FAILURES ===================================\n",
"\u001b[31m\u001b[1m____________________ notebook: nbregression(test_notebook2) ____________________\u001b[0m\n",
"pytest_notebook.nb_regression.NBRegressionError: Files differ and --nb-force-regen set, regenerating file at:\n",
"- /private/var/folders/dm/b2qnkb_n3r72slmpxlfmcjvm00lbnd/T/tmp11t_tnui/test_notebook2.ipynb\n",
"- /private/var/folders/dm/b2qnkb_n3r72slmpxlfmcjvm00lbnd/T/tmp8tzajwom/test_notebook2.ipynb\n",
"----------------------------- Captured stderr call -----------------------------\n",
"Diff before regeneration:\n",
"\n",
Expand All @@ -643,7 +644,7 @@
"\u001b[32m+\u001b[m\u001b[32mhallo2\u001b[m\n",
"\n",
"\u001b[0m\n",
"\u001b[31m\u001b[1m================ 1 failed, 1 passed, 1 warnings in 2.94 seconds ================\u001b[0m\n"
"\u001b[31m\u001b[1m================ 1 failed, 1 passed, 1 warnings in 2.92 seconds ================\u001b[0m\n"
]
}
],
Expand Down Expand Up @@ -681,7 +682,7 @@
"\u001b[1m============================= test session starts ==============================\u001b[0m\n",
"platform darwin -- Python 3.6.7, pytest-5.0.1, py-1.8.0, pluggy-0.12.0 -- //anaconda/envs/pytest_nb/bin/python\n",
"cachedir: .pytest_cache\n",
"rootdir: /private/var/folders/dm/b2qnkb_n3r72slmpxlfmcjvm00lbnd/T/tmpwqoc1myx\n",
"rootdir: /private/var/folders/dm/b2qnkb_n3r72slmpxlfmcjvm00lbnd/T/tmpn8nvkbye\n",
"plugins: cov-2.7.1, datadir-1.3.0, regressions-1.0.5, notebook-0.2.0\n",
"\u001b[1mcollecting ... \u001b[0mcollected 2 items\n",
"\n",
Expand All @@ -692,13 +693,13 @@
"\u001b[31m\u001b[1m________________________________ test_notebook1 ________________________________\u001b[0m\n",
"\n",
"nb_regression = NBRegressionFixture(exec_cwd='/var/folders/dm/b2qnkb_n3r72slmpxlfmcjvm00lbnd/T', exec_allow_errors=False, exec_timeout...place=(), diff_ignore=('/cells/*/outputs/*/traceback',), diff_use_color=True, diff_color_words=False, force_regen=True)\n",
"notebook = '/var/folders/dm/b2qnkb_n3r72slmpxlfmcjvm00lbnd/T/tmpiqn9v3sc.ipynb'\n",
"notebook = '/var/folders/dm/b2qnkb_n3r72slmpxlfmcjvm00lbnd/T/tmpzt9gftpf.ipynb'\n",
"\n",
"\u001b[1m def test_notebook1(nb_regression, notebook):\u001b[0m\n",
"\u001b[1m nb_regression.force_regen = True\u001b[0m\n",
"\u001b[1m> nb_regression.check(notebook)\u001b[0m\n",
"\u001b[1m\u001b[31mE pytest_notebook.nb_regression.NBRegressionError: Files differ and --nb-force-regen set, regenerating file at:\u001b[0m\n",
"\u001b[1m\u001b[31mE - /var/folders/dm/b2qnkb_n3r72slmpxlfmcjvm00lbnd/T/tmpiqn9v3sc.ipynb\u001b[0m\n",
"\u001b[1m\u001b[31mE - /var/folders/dm/b2qnkb_n3r72slmpxlfmcjvm00lbnd/T/tmpzt9gftpf.ipynb\u001b[0m\n",
"\n",
"\u001b[1m\u001b[31mtest_ipycell.py\u001b[0m:20: NBRegressionError\n",
"----------------------------- Captured stderr call -----------------------------\n",
Expand All @@ -717,7 +718,7 @@
"\u001b[32m+\u001b[m\u001b[32mhallo2\u001b[m\n",
"\n",
"\u001b[0m\n",
"\u001b[31m\u001b[1m================ 1 failed, 1 passed, 1 warnings in 2.98 seconds ================\u001b[0m\n"
"\u001b[31m\u001b[1m================ 1 failed, 1 passed, 1 warnings in 3.03 seconds ================\u001b[0m\n"
]
}
],
Expand Down
37 changes: 10 additions & 27 deletions pytest_notebook/execution.py
Expand Up @@ -12,35 +12,18 @@


class ExecutePreprocessorLogging(ExecutePreprocessor):
"""A subclass of ``nbconvert.ExecutePreprocessor`` that logs per cell execution."""
"""A subclass of ``nbconvert.ExecutePreprocessor`` with additional logging."""

def preprocess_cell(self, cell, resources, cell_index):
"""Execute a single code cell.
See base.py for details.
To execute all cells see :meth:`preprocess`.
"""
if cell.cell_type != "code" or not cell.source.strip():
return cell, resources

logger.info(f"Executing cell {cell_index}")
def preprocess(self, nb, resources, km=None):
"""Preprocess notebook executing each code cell."""
logger.info(f"About to execute notebook with {len(nb.cells)} cells")
return super().preprocess(nb, resources, km)

reply, outputs = self.run_cell(cell, cell_index)
# Backwards compatability for processes that wrap run_cell
cell.outputs = outputs

cell_allows_errors = (
self.allow_errors or "raises-exception" in cell.metadata.get("tags", [])
)

if self.force_raise_errors or not cell_allows_errors:
for out in cell.outputs:
if out.output_type == "error":
raise CellExecutionError.from_cell_and_msg(cell, out)
if (reply is not None) and reply["content"]["status"] == "error":
raise CellExecutionError.from_cell_and_msg(cell, reply["content"])
return cell, resources
def preprocess_cell(self, cell, resources, cell_index):
"""Execute a single code cell."""
if cell.cell_type == "code" and cell.source.strip():
logger.info(f"Executing cell {cell_index}")
return super().preprocess_cell(cell, resources, cell_index)


def execute_notebook(
Expand Down

0 comments on commit 77671f4

Please sign in to comment.