-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Skipping Notebook at runtime using pytest.exit("Not applicable on Frobble [skip-notebook]")
#43
Comments
For However, we don't know whether it is actually legit, and if you would accept a corresponding patch? for index, cell in enumerate(self.nb.cells):
try:
await self.async_execute_cell(
cell, index, execution_count=self.code_cells_executed + 1
)
except CellExecutionError as ex:
if ex.ename == "Skipped":
raise pytest.skip(ex.evalue)
else:
raise |
Hi again, we are now using a little of monkeypatching code in our Instead of using In order not to be too intrusive, the feature only skips notebooks when being explicitly instructed, by adding import os
import pytest
if "ACME_API_KEY" not in os.environ:
pytest.exit("ACME_API_KEY not given [skip-notebook]") We actually don't expect this "addon" to be mainlined in any way. Do you have any other suggestions how to proceed with this? With kind regards, |
pytest.exit("Not applicable on Frobble [skip-notebook]")
Hey hey! Cheers I'll try and have a look soon 😄 |
Another variant for the API, not relying on Let's consider this more elaborate snippet from our workbench where it is also made clear that "notebook skipping" is only a thing when actually running under pytest. import os
import getpass
# Skip testing notebook if API key is not supplied.
# When running interactively, prompt.
if "ACME_API_KEY" not in os.environ:
if "PYTEST_CURRENT_TEST" in os.environ:
import pytest_notebook
pytest_notebook.skip_notebook("ACME_API_KEY not given")
else:
os.environ["ACME_API_KEY"] = getpass.getpass("ACME API key:") The exception propagation and handling would probably be the same, only using a custom exception type this time, unless you are able to come up with a totally different mechanism. class SkipNotebook(Exception):
"""
Custom exception type to send a signal from the notebook to pytest-notebook
to stop test execution and mark the current test (scope?) as SKIPPED.
"""
pass
def skip_notebook(reason: str):
"""
Shorthand function to send "skip notebook" signal.
"""
raise SkipNotebook(reason) In this spirit, It feels like we are either telling a very esoteric story, or that we alternatively may be reinventing the wheel? ✨ |
I came here with precisely the same problem, and I'm having absolutely no luck skipping tests (using a variety of work-arounds). I tried the documented method of editing the notebooks metadata, adding:
to the notebook's metadata, and the |
Dear Chris,
thanks a stack for conceiving this excellent package.
We are using
pytest-notebook
with theJupyterNbCollector
, and investigated the capabilities how to conditionally skip notebooks while testing, but only found it to be possible using Notebook/Cell Metadata.In order to skip notebooks at runtime, based on other conditions, we will now detour to using a pytest-based test file, and invoke the notebooks using
NBRegressionFixture
. We guess this is the right choice?However, it looks like it may also be made possible to actually skip notebooks at runtime. This notebook code outlines that pytest's
Skipped
exception is already raised and propagated properly, so corresponding code inpytest-notebook
would only need to handle it appropriately?With kind regards,
Andreas.
The text was updated successfully, but these errors were encountered: