【问题标题】:Pytest and Tox ADB connect issue - Device unauthorizedPytest 和 Tox ADB 连接问题 - 设备未经授权
【发布时间】:2021-01-06 14:46:04
【问题描述】:

场景: 我正在尝试通过在 os.popen() 中使用 shell 命令将 ADB 连接到 Android 手机,作为自动化框架测试的一部分,我可以连接,但“adb 设备”将设备返回为已连接但未经授权,示例代码:

def test_connect_phone(self, phone):
        connect_stream = os.popen(f'adb connect {phone.host}:{phone.port}')
        print(connect_stream.read())
        install_stream = os.popen('adb devices')
        output = install_stream.read()
        print(output)
        assert output
# output
connected to <HOST>:<PORT>

List of devices attached
<HOST>:<PORT>   unauthorized

直接从终端运行相同的命令可以工作并且设备被授权:

adb connect <HOST>:<PORT>
adb devices

#output
connected to <HOST>:<PORT>

List of devices attached
<HOST>:<PORT>   device

注意:我将 tox 用于 pytest,这让我认为这可能是一个环境问题,但在测试中我看到在运行时我的主目录保持不变。 任何帮助表示赞赏。

【问题讨论】:

  • 这是否回答了您的问题,running adb devices showing unauthorized device?
  • 如果您将passenv = * 添加到您的tox.ini,您的测试是否失败?我的猜测是adb 需要一些特殊的环境变量,tox 正在过滤它——tox 核心开发人员之一
  • 找到了解决办法,显然我需要在“adb connect”之后添加 sleep(2),因为设备需要一段时间才能获得授权。

标签: python-3.x adb pytest tox


【解决方案1】:

找到了解决办法,显然我需要在“adb connect”之后添加 sleep(1),因为设备需要一段时间才能获得授权

【讨论】:

    猜你喜欢
    • 2015-10-16
    • 2014-05-29
    • 1970-01-01
    • 2014-10-03
    • 1970-01-01
    • 2014-11-30
    • 1970-01-01
    • 2018-04-04
    相关资源
    最近更新 更多