Skip to content

Commit da686bd

Browse files
Test that all modules can be imported
Add an integration test that imports all modules to ensure that all modules can be imported and that there are no circular imports. Signed-off-by: Daniel Zullo <[email protected]>
1 parent 3d8f31c commit da686bd

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,9 @@ max-attributes = 12
166166
testpaths = ["tests", "src"]
167167
asyncio_mode = "auto"
168168
required_plugins = ["pytest-asyncio", "pytest-mock"]
169+
markers = [
170+
"integration: integration tests (deselect with '-m \"not integration\"')",
171+
]
169172

170173
[tool.mypy]
171174
explicit_package_bases = true
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# License: MIT
2+
# Copyright © 2023 Frequenz Energy-as-a-Service GmbH
3+
4+
"""Tests to verify that all modules can be imported successfully."""
5+
6+
import importlib
7+
import os
8+
9+
import pytest
10+
11+
12+
@pytest.mark.integration
13+
def test_all_modules_importable() -> None:
14+
"""Test that all modules can be imported.
15+
16+
This test is mainly to ensure that there are no circular imports.
17+
"""
18+
src_path = "src"
19+
20+
for dir_path, _, files in os.walk(src_path):
21+
for file in files:
22+
if file.endswith(".py") and not file.startswith("__"):
23+
module_path = os.path.join(dir_path, file)
24+
module_name = os.path.splitext(module_path.replace(os.sep, "."))[0]
25+
26+
try:
27+
importlib.import_module(module_name)
28+
except ImportError as error:
29+
assert False, f"Failed to import {module_name}: {error}"

0 commit comments

Comments
 (0)