File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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
124import main
225
326def test_import_main ():
4- assert True # Просто проверяем, что импорт прошёл успешно
27+ assert True
You can’t perform that action at this time.
0 commit comments