Skip to content

Commit fec880f

Browse files
committed
test: добавлен тест импортов
1 parent d698af6 commit fec880f

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import pathlib
2+
import pytest
3+
4+
5+
class TestRelativeImports:
6+
"""Тест на отсутствие абсолютных путей в импортах проекта."""
7+
8+
def test_relative_imports(self):
9+
"""Проверяет отсутствие в проекте импортов с 'src'."""
10+
11+
src_dir = pathlib.Path("src")
12+
13+
files_with_src_imports = []
14+
15+
for py_file in src_dir.rglob("*.py"):
16+
content = py_file.read_text(encoding="utf-8")
17+
18+
for line_num, line in enumerate(content.splitlines(), 1):
19+
if line.strip().startswith('from src.') or line.strip().startswith('import src.'):
20+
relative_path = py_file.relative_to(src_dir)
21+
files_with_src_imports.append(f"{relative_path}:{line_num}")
22+
23+
if files_with_src_imports:
24+
error_msg = (
25+
"Найдены файлы с некорректными импортами:\n" +
26+
"\n".join(f" - {file}" for file in files_with_src_imports)
27+
)
28+
pytest.fail(error_msg)

0 commit comments

Comments
 (0)