test_imports

tests/test_imports.py
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
31
32
33
34
35
36
37
38
39
40
"""Test that all modules/packages in the lektor tree are importable in any order

Here we import each module by itself, one at a time, each in a new
python interpreter.

"""

import pkgutil
import sys
from subprocess import run

import pytest

import lektor_ng
from lektor_ng.markdown import MISTUNE_VERSION

ignored = set()

# Do not check importability of module for the non-installed version of mistune
if MISTUNE_VERSION.startswith("2"):
    ignored.add("lektor_ng.markdown.mistune0")
else:
    ignored.add("lektor_ng.markdown.mistune2")


def iter_lektor_modules():
    for module in pkgutil.walk_packages(lektor_ng.__path__, f"{lektor_ng.__name__}."):
        if module.name not in ignored:
            yield module.name


@pytest.fixture(params=iter_lektor_modules())
def module(request):
    return request.param


@pytest.mark.slowtest
def test_import(module):
    python = sys.executable
    assert run([python, "-c", f"import {module}"], check=False).returncode == 0