Skip to content

allow notebooks to exit early (e.g. with sys.exit(0) or pytest.skip(reason, allow_module_level=True)) #134

Description

@tswast

Is your feature request related to a problem? Please describe.

I have some notebooks that I test with multiple versions of Python, but they are not compatible with Python 3.13. I would love to be able to exit early from these notebooks without causing the test to be reported as a failure.

Describe the solution you'd like

I have tried the following cells:

import sys

# Python 3.13 is not yet a supported runtime.
if sys.version_info >= (3, 13, 0):
    sys.exit(0)

also

import sys

# Python 3.13 is not yet a supported runtime.
if sys.version_info >= (3, 13, 0):
    import pytest

    pytest.skip("Python 3.13 not supported", allow_module_level=True)

I would expect at least the latter to work, if not both. Note: one can disambiguate if SystemExit exception is "ok" / intended from a failure by looking at SystemExit.code == 0.

Describe alternatives you've considered

  • I've also tried creating an autouse fixture in a conftext.py file that wraps the yield in a try / except block to capture these expected exceptions, but it seems conftest.py fixtures don't run. Perhaps an alternative to consider to allow such flexibility.

  • I've tried the "metadata": { "tags": [ "raises-exception" ] } on the cell, but this actually continues execution after the failed cell. I suspect this is desirable to have code cells that demonstrate exceptions, but it wasn't the right solution to be able to exit early.

Additional context

N/A

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesthelp wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions