File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11try :
22 from pynput .keyboard import Key , Listener
3- except ImportError :
4- msg = (
5- "[ERROR] 'pynput' no está instalado. "
6- "Instálalo con 'pip install pynput'"
7- )
8- print (msg )
3+ except (ImportError , Exception ):
4+ # En entornos sin GUI (como algunos CI), pynput puede fallar al importar
5+ Key = None
96 Listener = None
107
118
@@ -37,13 +34,14 @@ def on_press(self, key):
3734 print (f"[Captured] { k } " )
3835
3936 def on_release (self , key ):
40- if key == Key .esc :
37+ if not Key or key == Key .esc :
4138 # Detener el listener con la tecla ESC
42- print ("[*] Deteniendo captura (ESC presionado )..." )
39+ print ("[*] Deteniendo captura (ESC o entorno sin soporte )..." )
4340 return False
4441
4542 def start (self ):
4643 if not Listener :
44+ print ("[!] Listener no disponible en este entorno." )
4745 return
4846
4947 msg = f"[*] Iniciando escucha... Logs en: { self .output_file } "
Original file line number Diff line number Diff line change 77# Mocking Listener and Key from pynput
88@pytest .fixture
99def mock_pynput ():
10- with patch ('src.core.engine.Listener' ) as mock_listener , \
11- patch ('src.core.engine.Key' ) as mock_key :
10+ # Usamos create=True por si pynput no se pudo importar en el entorno de test
11+ with patch ('src.core.engine.Listener' , create = True ) as mock_listener , \
12+ patch ('src.core.engine.Key' , create = True ) as mock_key :
1213 yield mock_listener , mock_key
1314
1415
@@ -43,7 +44,7 @@ def test_engine_on_release_esc(mock_pynput):
4344 assert result is False
4445
4546
46- @patch ('src.core.engine.Listener' )
47+ @patch ('src.core.engine.Listener' , create = True )
4748def test_engine_start_calls_listener (mock_listener ):
4849 """Verifica que engine.start() inicie el Listener."""
4950 engine = RealEngine ()
You can’t perform that action at this time.
0 commit comments