Skip to content

Commit d1ebfbb

Browse files
committed
Update test_smoke.py
1 parent f2a79d5 commit d1ebfbb

1 file changed

Lines changed: 24 additions & 1 deletion

File tree

test_smoke.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,27 @@
1+
import sys
2+
import types
3+
4+
# Создаем класс-заглушку, который имитирует поведение Listener
5+
class MockListener:
6+
def __init__(self, on_press=None):
7+
self.on_press = on_press
8+
def __enter__(self):
9+
return self
10+
def __exit__(self, exc_type, exc_val, exc_tb):
11+
pass
12+
def join(self):
13+
pass
14+
15+
# Создаем мок-модуль keyboard
16+
mock_keyboard = types.ModuleType("pynput.keyboard")
17+
mock_keyboard.Listener = MockListener
18+
19+
# Подменяем модули в sys.modules
20+
sys.modules["pynput"] = types.ModuleType("pynput")
21+
sys.modules["pynput.keyboard"] = mock_keyboard
22+
23+
# Теперь можно безопасно импортировать main, даже если там используется pynput.keyboard.Listener
124
import main
225

326
def test_import_main():
4-
assert True # Просто проверяем, что импорт прошёл успешно
27+
assert True

0 commit comments

Comments
 (0)