Coverage for /home/runner/.local/share/hatch/env/virtual/importnb/KA2AwMZG/test.stdlib/lib/python3.9/site-packages/importnb/utils/pytest_importnb.py: 58%
24 statements
« prev ^ index » next coverage.py v7.3.2, created at 2023-11-02 04:02 +0000
« prev ^ index » next coverage.py v7.3.2, created at 2023-11-02 04:02 +0000
1# coding: utf-8
2"""A `pytest` plugin for importing notebooks as modules and using standard test discovered.
4The `AlternativeModule` is reusable. See `pidgin` for an example.
5"""
7from pathlib import Path
9import pytest
11from importnb import Notebook
14def get_file_patterns(cls, parent):
15 for pat in parent.config.getini("python_files"):
16 for e in cls.loader().extensions:
17 yield "*" + pat.rstrip(".py") + e
20class AlternativeModule(pytest.Module):
21 def _getobj(self):
22 return self.loader.load_file(str(self.path), False)
24 @classmethod
25 def pytest_collect_file(cls, parent, path):
26 if not parent.session.isinitpath(path): 26 ↛ 33line 26 didn't jump to line 33, because the condition on line 26 was never false
27 for pat in get_file_patterns(cls, parent):
28 if path.fnmatch(pat):
29 break
30 else:
31 return
33 if hasattr(cls, "from_parent"): 33 ↛ 35line 33 didn't jump to line 35, because the condition on line 33 was never false
34 return cls.from_parent(parent, path=Path(path))
35 return cls(path, parent)
38class NotebookModule(AlternativeModule):
39 loader = Notebook
42pytest_collect_file = NotebookModule.pytest_collect_file