Skip to content
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

Add notebook markers #95

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions src/nbmake/pytest_items.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from pygments.lexers import Python3TracebackLexer

from .nb_result import NotebookError, NotebookResult
from .nb_run import NotebookRun
from .nb_run import NB_VERSION, NotebookRun


class NbMakeFailureRepr(TerminalRepr):
Expand All @@ -26,7 +26,20 @@ def toterminal(self, tw: TerminalWriter) -> None:

class NotebookFile(pytest.File):
def collect(self) -> Generator[Any, Any, Any]:
yield NotebookItem.from_parent(self, filename=str(Path(self.fspath)))
item = NotebookItem.from_parent(self, filename=str(Path(self.fspath)))

with open(self.fspath, "rb") as fp:
nb = nbformat.read(fp, NB_VERSION)

markers = nb.metadata.get("execution", {}).get("nbmake", {}).get("markers", [])

if isinstance(markers, str):
markers = [marker.strip() for marker in markers.split(",")]

for marker in markers:
item.add_marker(marker)

yield item


class NotebookFailedException(Exception):
Expand Down
Loading