Airtest
Airtest copied to clipboard
同时运行多个case,总有case跑失败,经常报BrokenPipeError: [Errno 32] Broken pipe
前置条件: 机型:电脑:macOS Mojave 10.14.5 手机:iphone8p 系统11.0 xcode 11.2.1 使用unittest框架,一个接着一个跑case,总会有case跑失败;而这些case单独一个个在airtest客户端内调试是成功的
报错如下: `Traceback (most recent call last): File "/usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 601, in urlopen chunked=chunked) File "/usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 357, in _make_request conn.request(method, url, **httplib_request_kw) File "/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1239, in request self._send_request(method, url, body, headers, encode_chunked) File "/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1285, in _send_request self.endheaders(body, encode_chunked=encode_chunked) File "/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1234, in endheaders self._send_output(message_body, encode_chunked=encode_chunked) File "/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1026, in _send_output self.send(msg) File "/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 986, in send self.sock.sendall(data) BrokenPipeError: [Errno 32] Broken pipe
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "/usr/local/lib/python3.6/site-packages/requests/adapters.py", line 440, in send timeout=timeout File "/usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 639, in urlopen _stacktrace=sys.exc_info()[2]) File "/usr/local/lib/python3.6/site-packages/urllib3/util/retry.py", line 357, in increment raise six.reraise(type(error), error, _stacktrace) File "/usr/local/lib/python3.6/site-packages/urllib3/packages/six.py", line 685, in reraise raise value.with_traceback(tb) File "/usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 601, in urlopen chunked=chunked) File "/usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 357, in _make_request conn.request(method, url, **httplib_request_kw) File "/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1239, in request self._send_request(method, url, body, headers, encode_chunked) File "/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1285, in _send_request self.endheaders(body, encode_chunked=encode_chunked) File "/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1234, in endheaders self._send_output(message_body, encode_chunked=encode_chunked) File "/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1026, in _send_output self.send(msg) File "/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 986, in send self.sock.sendall(data) urllib3.exceptions.ProtocolError: ('Connection aborted.', BrokenPipeError(32, 'Broken pipe'))
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "/usr/local/lib/python3.6/site-packages/airtest/utils/logwraper.py", line 72, in wrapper res = f(*args, **kwargs) File "/usr/local/lib/python3.6/site-packages/airtest/core/api.py", line 259, in touch try_log_screen() File "/usr/local/lib/python3.6/site-packages/airtest/utils/logwraper.py", line 72, in wrapper res = f(*args, **kwargs) File "/usr/local/lib/python3.6/site-packages/airtest/core/cv.py", line 97, in try_log_screen screen = G.DEVICE.snapshot() File "/usr/local/lib/python3.6/site-packages/airtest/core/ios/ios.py", line 159, in snapshot data = self._neo_wda_screenshot() # wda 截图不用考虑朝向 File "/usr/local/lib/python3.6/site-packages/airtest/core/ios/ios.py", line 143, in _neo_wda_screenshot value = self.driver.http.get('screenshot').value File "/usr/local/lib/python3.6/site-packages/wda/init.py", line 129, in fetch return self._fetch_no_alert(method, url, data) File "/usr/local/lib/python3.6/site-packages/wda/init.py", line 135, in _fetch_no_alert return httpdo(target_url, method, data) File "/usr/local/lib/python3.6/site-packages/wda/init.py", line 95, in httpdo response = requests.request(method, url, json=data, timeout=HTTP_TIMEOUT) File "/usr/local/lib/python3.6/site-packages/requests/api.py", line 58, in request return session.request(method=method, url=url, **kwargs) File "/usr/local/lib/python3.6/site-packages/requests/sessions.py", line 502, in request resp = self.send(prep, **send_kwargs) File "/usr/local/lib/python3.6/site-packages/requests/sessions.py", line 612, in send r = adapter.send(request, **kwargs) File "/usr/local/lib/python3.6/site-packages/requests/adapters.py", line 490, in send raise ConnectionError(err, request=request) requests.exceptions.ConnectionError: ('Connection aborted.', BrokenPipeError(32, 'Broken pipe'))`
我这边最近也出现这个问题,在特定的机型上显示比较多比如华为mate10,换了手机后基本不出现。 我后来把每个case的最后断开poco或者其它socket连接最后发送请求的代码前面停留10S,加个try后面很少出现了 我也在等官方给的解决方案
我这边是mac设备 多个需要adb的进程存在时,运行测试会出现
运行到一半崩了
为了防止停止不干净,还等待了30s,没啥用。大家还有什么解决方案吗? poco.stop_running() subprocess.call(['adb', "-s", device_id, 'kill-server']) sleep(30) # 避免BrokenPipeError subprocess.call(['adb', "-s", device_id, 'start-server']) subprocess.call(['adb', "-s", device_id, 'devices'])