nbmake icon indicating copy to clipboard operation
nbmake copied to clipboard

Add notebook markers

Open mcflugen opened this issue 2 years ago • 4 comments

Apologies for the unsolicited pull request. I've added a small bit of functionality to nbmake that we have found to be useful and thought others might as well.

This pull request allows users to mark notebooks in a way similar to what one might do with @pytest.mark. Markers are included within a notebook's metadata much like how the allow_errors and timeout options are specified. As an example,

{
  "cells": [ ... ],
  "metadata": {
    "kernelspec": { ... },
    "execution": {
      "markers": ["slow"]
    }
  }
}

would mark this notebook as "slow".

Markers can be either an array of strings (i.e. ["slow", "memory_intensive") or a string of comma-separated markers (i.e. "slow,memory_intensive"). Notebooks can then be included or excluded in the tests through the -m option just as with other pytest tests (e.g. pytest **/*.ipynb -m "slow and not memory_intensive" would only run notebooks that are slow but not memory intensive).

If this is something you think could be a part of nbmake (great!), I can add some tests and write a bit of documentation to go with this. If not, no worries.

mcflugen avatar Feb 10 '23 04:02 mcflugen

Codecov Report

Merging #95 (3e86d46) into main (966edac) will decrease coverage by 0.37%. The diff coverage is 89.58%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main      #95      +/-   ##
==========================================
- Coverage   92.46%   92.10%   -0.37%     
==========================================
  Files           4        4              
  Lines         146      190      +44     
==========================================
+ Hits          135      175      +40     
- Misses         11       15       +4     
Impacted Files Coverage Δ
src/nbmake/pytest_plugin.py 91.66% <83.33%> (-3.08%) :arrow_down:
src/nbmake/pytest_items.py 87.30% <84.61%> (-1.16%) :arrow_down:
src/nbmake/nb_run.py 94.62% <93.10%> (+0.77%) :arrow_up:

codecov[bot] avatar Feb 10 '23 09:02 codecov[bot]

Thanks @mcflugen for this contribution, it's a great idea for a feature.

Some notes:

  • py 3.7 tests are failing, please ignore
  • We should probably namespace metadata fields specific to nbmake like we do for mocks
  • Please add a test to ensure that this does not change the failure mode for notebooks that cannot be read (e.g. because they are not valid JSON)
    • I can help with this if you are not sure how

alex-treebeard avatar Feb 10 '23 09:02 alex-treebeard