treebeardtech / nbmake

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

Add notebook markers #95

Open mcflugen opened 1 year ago

mcflugen commented 1 year ago

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.

codecov[bot] commented 1 year ago

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:
alex-treebeard commented 1 year ago

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

Some notes: