From 577e894b7d5c6a3e1c8486d13a7573d87209047b Mon Sep 17 00:00:00 2001 From: mcflugen Date: Mon, 6 Feb 2023 23:27:58 -0700 Subject: [PATCH 1/4] read markers from notebook metadata --- src/nbmake/pytest_items.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/nbmake/pytest_items.py b/src/nbmake/pytest_items.py index ed69d9b..75ee058 100644 --- a/src/nbmake/pytest_items.py +++ b/src/nbmake/pytest_items.py @@ -25,7 +25,22 @@ 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))) + + nb = nbformat.read(self.fspath, 4) + + try: + markers = nb.metadata.execution.markers + except AttributeError: + markers = [] + + if isinstance(markers, str): + markers = markers.split(",") + + for marker in markers: + item.add_marker(marker) + + yield item class NotebookFailedException(Exception): From 32a5d0edcfb2bcb090c58df36c18a3f4ba2af0a8 Mon Sep 17 00:00:00 2001 From: mcflugen Date: Tue, 7 Feb 2023 09:45:08 -0700 Subject: [PATCH 2/4] open notebook as binary --- src/nbmake/pytest_items.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/nbmake/pytest_items.py b/src/nbmake/pytest_items.py index 75ee058..db4c9ba 100644 --- a/src/nbmake/pytest_items.py +++ b/src/nbmake/pytest_items.py @@ -11,7 +11,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): @@ -27,7 +27,8 @@ class NotebookFile(pytest.File): def collect(self) -> Generator[Any, Any, Any]: item = NotebookItem.from_parent(self, filename=str(Path(self.fspath))) - nb = nbformat.read(self.fspath, 4) + with open(self.fspath, "rb") as fp: + nb = nbformat.read(fp, NB_VERSION) try: markers = nb.metadata.execution.markers From f06d44af83a920bd57667adec4f5f2c6927dfed6 Mon Sep 17 00:00:00 2001 From: mcflugen Date: Sun, 22 Sep 2024 11:43:04 -0600 Subject: [PATCH 3/4] move markers into nbmake namespace --- src/nbmake/pytest_items.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/nbmake/pytest_items.py b/src/nbmake/pytest_items.py index 4fe9f58..8f8d397 100644 --- a/src/nbmake/pytest_items.py +++ b/src/nbmake/pytest_items.py @@ -31,10 +31,7 @@ def collect(self) -> Generator[Any, Any, Any]: with open(self.fspath, "rb") as fp: nb = nbformat.read(fp, NB_VERSION) - try: - markers = nb.metadata.execution.markers - except AttributeError: - markers = [] + markers = nb.metadata.get("execution", {}).get("nbmake", {}).get("markers", []) if isinstance(markers, str): markers = markers.split(",") From 90ca0a3a3fb099be0f08f87a9147d286c67437d0 Mon Sep 17 00:00:00 2001 From: mcflugen Date: Sun, 22 Sep 2024 11:45:25 -0600 Subject: [PATCH 4/4] strip whitespace from around markers --- src/nbmake/pytest_items.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nbmake/pytest_items.py b/src/nbmake/pytest_items.py index 8f8d397..f3b8a64 100644 --- a/src/nbmake/pytest_items.py +++ b/src/nbmake/pytest_items.py @@ -34,7 +34,7 @@ def collect(self) -> Generator[Any, Any, Any]: markers = nb.metadata.get("execution", {}).get("nbmake", {}).get("markers", []) if isinstance(markers, str): - markers = markers.split(",") + markers = [marker.strip() for marker in markers.split(",")] for marker in markers: item.add_marker(marker)