blob: 437094c3860e51ca9eabfb794766e98f640b0ffe (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
import pytest
from snakeoil.test import mixins
class TestDemandLoadTargets(mixins.PythonNamespaceWalker):
target_namespace = "snakeoil"
ignore_all_import_failures = False
@pytest.fixture(autouse=True)
def _setup(self):
self._failures = []
yield
msg = "\n".join(sorted(f"{target}: error {e}" for target, e in self._failures))
assert not self._failures, "bad demandload targets:\n" + msg
def test_demandload_targets(self):
for x in self.walk_namespace(
self.target_namespace, ignore_failed_imports=self.ignore_all_import_failures
):
self.check_space(x)
def check_space(self, mod):
for attr in dir(mod):
try:
obj = getattr(mod, attr)
# force __getattribute__ to fire
getattr(obj, "__class__", None)
except ImportError as ie:
# hit one.
self._failures.append((f"{mod.__name__}: target {attr}", ie))
|