forked from appium/python-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_helper.py
More file actions
33 lines (23 loc) · 735 Bytes
/
test_helper.py
File metadata and controls
33 lines (23 loc) · 735 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import os
import socket
class NoAvailablePortError(Exception):
pass
def get_available_from_port_range(from_port, to_port):
"""Returns available local port number.
"""
r = range(from_port, to_port)
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
for port in r:
try:
if sock.connect_ex(('localhost', port)) != 0:
return port
finally:
sock.close()
raise NoAvailablePortError('No available port between {} and {}'.format(
from_port, to_port))
def is_ci():
"""Returns if current execution is running on CI
Returns:
bool: `True` if current executions is on CI
"""
return os.getenv('CI', 'false') == 'true'