Best Python code snippet using avocado_python
check_port.py
Source:check_port.py
...16 return True17 else:18 print('port %s already be in use !' % port)19 return False20def release_port(port):21 """éæ¾æå®ç端å£"""22 cmd_find = 'netstat -aon | findstr {}'.format(port) # æ¥æ¾å¯¹åºç«¯å£çpid23 # è¿åå½ä»¤æ§è¡åçç»æ24 result = os.popen(cmd_find).read()25 if str(port) and 'LISTENING' in result:26 # è·å端å£å¯¹åºçpidè¿ç¨27 i = result.index('LISTENING')28 start = i + len('LISTENING') + 729 end = result.index('\n')30 pid = result[start:end]31 cmd_kill = 'taskkill -f -pid %s' % pid # å
³é被å ç¨ç«¯å£çpid32 os.popen(cmd_kill)33 print(f'éæ¾è¿ç¨ç«¯å£:{port}')34 else:35 print('port %s is available !' % port)36if __name__ == '__main__':37 host = '127.0.0.1'38 port = 472339 release_port(4723)40 release_port(4725)41 if not check_port(host, port):42 print("端å£è¢«å ç¨")...
test_utils_network.py
Source:test_utils_network.py
...15 def test_release_port_does_not_poke_system(self):16 tracker = network.PortTracker()17 tracker.release_port = mock.MagicMock()18 network.is_port_free = mock.MagicMock()19 tracker.release_port(22)20 tracker.release_port.assert_called_once_with(22)21 network.is_port_free.assert_not_called()22 def test_release_port(self):23 tracker = network.PortTracker()24 tracker.retained_ports = [22]25 tracker.release_port(22)26 self.assertNotIn(22, tracker.retained_ports)27if __name__ == "__main__":...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!