treebeardtech / nbmake

📝 Pytest plugin for testing notebooks
https://pypi.org/project/nbmake/
Apache License 2.0
179 stars 18 forks source link

Support for running arbitrary hidden code after a cell runs #93

Closed tekumara closed 1 year ago

tekumara commented 1 year ago

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

When running in CI, I'd like to run arbitrary code after a cell has run, to configure the notebook for the CI environment.

eg: Suppose I have a notebook cell with:

access_token = "EXAMPLE" 

When running the notebook via nbmake, after this cell runs I'd like to be able to fetch and set the token from a secret store, eg:

import os, boto3
if os.getenv("CI"):
    client = boto3.client("secretsmanager")
    access_token = client.get_secret_value(SecretId="the_token_arn")["SecretString"]

Describe the solution you'd like

Potentially this could work similar to the mock functionality, ie: specified via cell metadata.

Describe alternatives you've considered

Without these I'd have to include the secret fetching in the notebook cell. But I'd rather not expose that detail to end users reading the notebook, because its only really relevant for CI, and not when they use the notebook themselves.