

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 在 AWS Device Farm 中对 Appium Python 测试进行故障排除
<a name="troubleshooting-appium-python"></a>

以下主题列出了在上传 Appium Python 测试期间出现的错误消息并推荐了解决方法来解决每个错误。

## APPIUM\$1PYTHON\$1TEST\$1PACKAGE\$1UNZIP\$1FAILED
<a name="APPIUM_PYTHON_TEST_PACKAGE_UNZIP_FAILED"></a>

如果您看到以下消息，请执行以下步骤来修复此问题。

**警告**  
我们无法打开您的 Appium 测试 ZIP 文件。请验证文件是否有效，然后重试。

确保您可以解压测试程序包，而不会出现错误。在以下示例中，程序包的名称为 **test\$1bundle.zip**。

1. 将您的测试程序包复制到工作目录，然后运行以下命令：

   ```
   $ unzip test_bundle.zip
   ```

1. 成功解压缩程序包后，您可以通过运行以下命令找到工作目录树结构：

   ```
   $ tree .
   ```

   有效的 Appium Python 程序包应生成类似以下内容的输出：

   ```
   .
   |-- requirements.txt
   |-- test_bundle.zip
   |-- tests (directory)
   |      `-- test_unittest.py
   `-- wheelhouse (directory)
          |-- Appium_Python_Client-0.20-cp27-none-any.whl
          |-- py-1.4.31-py2.py3-none-any.whl
          |-- pytest-2.9.0-py2.py3-none-any.whl
          |-- selenium-2.52.0-cp27-none-any.whl
          `-- wheel-0.26.0-py2.py3-none-any.whl
   ```

   有关更多信息，请参阅 [在 Device Farm 中自动运行 Appium 测试将 Appium 测试与 Device Farm 集成](test-types-appium.md)。

## APPIUM\$1PYTHON\$1TEST\$1PACKAGE\$1DEPENDENCY\$1WHEEL\$1MISSING
<a name="APPIUM_PYTHON_TEST_PACKAGE_DEPENDENCY_WHEEL_MISSING"></a>

如果您看到以下消息，请执行以下步骤来修复此问题。

**警告**  
我们无法在 wheelhouse 目录树中找到依赖项 wheel 文件。请解压缩您的测试程序包，打开 wheelhouse 目录，并验证至少有一个 wheel 文件在该目录中，然后重试。

确保您可以解压测试程序包，而不会出现错误。在以下示例中，程序包的名称为 **test\$1bundle.zip**。

1. 将您的测试程序包复制到工作目录，然后运行以下命令：

   ```
   $ unzip test_bundle.zip
   ```

1. 成功解压缩程序包后，您可以通过运行以下命令找到工作目录树结构：

   ```
   $ tree .
   ```

   如果 Appium Python 程序包有效，您将在 *wheelhouse* 目录中找到至少一个类似于突出显示的文件的 *.whl* 依赖项文件。

   ```
   .
   |-- requirements.txt
   |-- test_bundle.zip
   |-- tests (directory)
   |      `-- test_unittest.py
   `-- wheelhouse (directory)
          |-- Appium_Python_Client-0.20-cp27-none-any.whl
          |-- py-1.4.31-py2.py3-none-any.whl
          |-- pytest-2.9.0-py2.py3-none-any.whl
          |-- selenium-2.52.0-cp27-none-any.whl
          `-- wheel-0.26.0-py2.py3-none-any.whl
   ```

   有关更多信息，请参阅 [在 Device Farm 中自动运行 Appium 测试将 Appium 测试与 Device Farm 集成](test-types-appium.md)。

## APPIUM\$1PYTHON\$1TEST\$1PACKAGE\$1INVALID\$1PLATFORM
<a name="APPIUM_PYTHON_TEST_PACKAGE_INVALID_PLATFORM"></a>

如果您看到以下消息，请执行以下步骤来修复此问题。

**警告**  
我们发现至少有一个 wheel 文件指定了我们不支持的平台。请解压缩您的测试程序包，打开 wheelhouse 目录，并验证 wheel 文件的名称以 -any.whl 或 -linux\$1x86\$164.whl 结尾，然后重试。

确保您可以解压测试程序包，而不会出现错误。在以下示例中，程序包的名称为 **test\$1bundle.zip**。

1. 将您的测试程序包复制到工作目录，然后运行以下命令：

   ```
   $ unzip test_bundle.zip
   ```

1. 成功解压缩程序包后，您可以通过运行以下命令找到工作目录树结构：

   ```
   $ tree .
   ```

   如果 Appium Python 程序包有效，您将在 *wheelhouse* 目录中找到至少一个类似于突出显示的文件的 *.whl* 依赖项文件。文件的名称可能不同，但它应以指定该平台的 *-any.whl* 或 *-linux\$1x86\$164.whl* 结尾。其他任何平台，如 `windows`，均不受支持。

   ```
   .
   |-- requirements.txt
   |-- test_bundle.zip
   |-- tests (directory)
   |      `-- test_unittest.py
   `-- wheelhouse (directory)
          |-- Appium_Python_Client-0.20-cp27-none-any.whl
          |-- py-1.4.31-py2.py3-none-any.whl
          |-- pytest-2.9.0-py2.py3-none-any.whl
          |-- selenium-2.52.0-cp27-none-any.whl
          `-- wheel-0.26.0-py2.py3-none-any.whl
   ```

   有关更多信息，请参阅 [在 Device Farm 中自动运行 Appium 测试将 Appium 测试与 Device Farm 集成](test-types-appium.md)。

## APPIUM\$1PYTHON\$1TEST\$1PACKAGE\$1TEST\$1DIR\$1MISSING
<a name="APPIUM_PYTHON_TEST_PACKAGE_TEST_DIR_MISSING"></a>

如果您看到以下消息，请执行以下步骤来修复此问题。

**警告**  
我们无法在您的测试程序包中找到 tests 目录。请解压缩您的测试程序包，验证 tests 目录位于该程序包中，然后重试。

确保您可以解压测试程序包，而不会出现错误。在以下示例中，程序包的名称为 **test\$1bundle.zip**。

1. 将您的测试程序包复制到工作目录，然后运行以下命令：

   ```
   $ unzip test_bundle.zip
   ```

1. 成功解压缩程序包后，您可以通过运行以下命令找到工作目录树结构：

   ```
   $ tree .
   ```

   如果 Appium Python 程序包有效，您将在工作目录中找到 *tests* 目录。

   ```
   .
   |-- requirements.txt
   |-- test_bundle.zip
   |-- tests (directory)
   |      `-- test_unittest.py
   `-- wheelhouse (directory)
          |-- Appium_Python_Client-0.20-cp27-none-any.whl
          |-- py-1.4.31-py2.py3-none-any.whl
          |-- pytest-2.9.0-py2.py3-none-any.whl
          |-- selenium-2.52.0-cp27-none-any.whl
          `-- wheel-0.26.0-py2.py3-none-any.whl
   ```

   有关更多信息，请参阅 [在 Device Farm 中自动运行 Appium 测试将 Appium 测试与 Device Farm 集成](test-types-appium.md)。

## APPIUM\$1PYTHON\$1TEST\$1PACKAGE\$1INVALID\$1TEST\$1FILE\$1NAME
<a name="APPIUM_PYTHON_TEST_PACKAGE_INVALID_TEST_FILE_NAME"></a>

如果您看到以下消息，请执行以下步骤来修复此问题。

**警告**  
我们无法在 tests 目录树中找到有效的测试文件。请解压缩您的程序包，打开 tests 目录，并验证至少有一个文件的名称以关键字“test”开头或结尾，然后重试。

确保您可以解压测试程序包，而不会出现错误。在以下示例中，程序包的名称为 **test\$1bundle.zip**。

1. 将您的测试程序包复制到工作目录，然后运行以下命令：

   ```
   $ unzip test_bundle.zip
   ```

1. 成功解压缩程序包后，您可以通过运行以下命令找到工作目录树结构：

   ```
   $ tree .
   ```

   如果 Appium Python 程序包有效，您将在工作目录中找到 *tests* 目录。文件的名称可能不同，但它应以 *test\$1* 开头或以 *\$1test.py* 结尾。

   ```
   .
   |-- requirements.txt
   |-- test_bundle.zip
   |-- tests (directory)
   |      `-- test_unittest.py
   `-- wheelhouse (directory)
          |-- Appium_Python_Client-0.20-cp27-none-any.whl
          |-- py-1.4.31-py2.py3-none-any.whl
          |-- pytest-2.9.0-py2.py3-none-any.whl
          |-- selenium-2.52.0-cp27-none-any.whl
          `-- wheel-0.26.0-py2.py3-none-any.whl
   ```

   有关更多信息，请参阅 [在 Device Farm 中自动运行 Appium 测试将 Appium 测试与 Device Farm 集成](test-types-appium.md)。

## APPIUM\$1PYTHON\$1TEST\$1PACKAGE\$1REQUIREMENTS\$1TXT\$1FILE\$1MISSING
<a name="APPIUM_PYTHON_TEST_PACKAGE_REQUIREMENTS_TXT_FILE_MISSING"></a>

如果您看到以下消息，请执行以下步骤来修复此问题。

**警告**  
我们无法在您的测试程序包中找到 requirements.txt 文件。请解压缩您的测试程序包，验证 requirements.txt 文件位于该程序包中，然后重试。

确保您可以解压测试程序包，而不会出现错误。在以下示例中，程序包的名称为 **test\$1bundle.zip**。

1. 将您的测试程序包复制到工作目录，然后运行以下命令：

   ```
   $ unzip test_bundle.zip
   ```

1. 成功解压缩程序包后，您可以通过运行以下命令找到工作目录树结构：

   ```
   $ tree .
   ```

   如果 Appium Python 程序包有效，您将在工作目录中找到 *requirements.txt* 文件。

   ```
   .
   |-- requirements.txt
   |-- test_bundle.zip
   |-- tests (directory)
   |      `-- test_unittest.py
   `-- wheelhouse (directory)
          |-- Appium_Python_Client-0.20-cp27-none-any.whl
          |-- py-1.4.31-py2.py3-none-any.whl
          |-- pytest-2.9.0-py2.py3-none-any.whl
          |-- selenium-2.52.0-cp27-none-any.whl
          `-- wheel-0.26.0-py2.py3-none-any.whl
   ```

   有关更多信息，请参阅 [在 Device Farm 中自动运行 Appium 测试将 Appium 测试与 Device Farm 集成](test-types-appium.md)。

## APPIUM\$1PYTHON\$1TEST\$1PACKAGE\$1INVALID\$1PYTEST\$1VERSION
<a name="APPIUM_PYTHON_TEST_PACKAGE_INVALID_PYTEST_VERSION"></a>

如果您看到以下消息，请执行以下步骤来修复此问题。

**警告**  
我们发现 pytest 版本低于我们支持的最低版本 2.8.0。请更改 requirements.txt 文件内的 pytest 版本，然后重试。

确保您可以解压测试程序包，而不会出现错误。在以下示例中，程序包的名称为 **test\$1bundle.zip**。

1. 将您的测试程序包复制到工作目录，然后运行以下命令：

   ```
   $ unzip test_bundle.zip
   ```

1. 成功解压缩程序包后，您可以通过运行以下命令找到工作目录树结构：

   ```
   $ tree .
   ```

   您应在工作目录中找到 *requirements.txt* 文件。

   ```
   .
   |-- requirements.txt
   |-- test_bundle.zip
   |-- tests (directory)
   |      `--test_unittest.py
   `-- wheelhouse (directory)
          |-- Appium_Python_Client-0.20-cp27-none-any.whl
          |-- py-1.4.31-py2.py3-none-any.whl
          |-- pytest-2.9.0-py2.py3-none-any.whl
          |-- selenium-2.52.0-cp27-none-any.whl
          `-- wheel-0.26.0-py2.py3-none-any.whl
   ```

1. 要获取 pytest 版本，您可以运行以下命令：

   ```
   $ grep "pytest" requirements.txt
   ```

   您应找到类似以下内容的输出：

   ```
   pytest==2.9.0
   ```

   它显示了 pytest 版本，在本例中为 2.9.0。如果 Appium Python 程序包有效，pytest 版本应当高于或等于 2.8.0。

   有关更多信息，请参阅 [在 Device Farm 中自动运行 Appium 测试将 Appium 测试与 Device Farm 集成](test-types-appium.md)。

## APPIUM\$1PYTHON\$1TEST\$1PACKAGE\$1INSTALL\$1DEPENDENCY\$1WHEELS\$1FAILED
<a name="APPIUM_PYTHON_TEST_PACKAGE_INSTALL_DEPENDENCY_WHEELS_FAILED"></a>

如果您看到以下消息，请执行以下步骤来修复此问题。

**警告**  
我们未能安装依赖项 wheel。请解压缩您的测试程序包，打开 requirements.txt 文件和 wheelhouse 目录，并验证 requirements.txt 文件中指定的依赖项 wheel 与 wheelhouse 目录中的依赖项 wheel 完全匹配，然后重试。

我们强烈建议您为包装测试设置 [Python virtualenv](https://pypi.python.org/pypi/virtualenv)。以下是使用 Python virtualenv 创建虚拟环境然后将其激活的示例流程：

```
$ virtualenv workspace
$ cd workspace 
$ source bin/activate
```

确保您可以解压测试程序包，而不会出现错误。在以下示例中，程序包的名称为 **test\$1bundle.zip**。

1. 将您的测试程序包复制到工作目录，然后运行以下命令：

   ```
   $ unzip test_bundle.zip
   ```

1. 要测试安装 wheel 文件，您可以运行以下命令：

   ```
   $ pip install --use-wheel --no-index --find-links=./wheelhouse --requirement=./requirements.txt
   ```

   有效的 Appium Python 程序包应生成类似以下内容的输出：

   ```
   Ignoring indexes: https://pypi.python.org/simple
   Collecting Appium-Python-Client==0.20 (from -r ./requirements.txt (line 1))
   Collecting py==1.4.31 (from -r ./requirements.txt (line 2))
   Collecting pytest==2.9.0 (from -r ./requirements.txt (line 3))
   Collecting selenium==2.52.0 (from -r ./requirements.txt (line 4))
   Collecting wheel==0.26.0 (from -r ./requirements.txt (line 5))
   Installing collected packages: selenium, Appium-Python-Client, py, pytest, wheel
     Found existing installation: wheel 0.29.0
       Uninstalling wheel-0.29.0:
         Successfully uninstalled wheel-0.29.0
   Successfully installed Appium-Python-Client-0.20 py-1.4.31 pytest-2.9.0 selenium-2.52.0 wheel-0.26.0
   ```

1. 要停用虚拟环境，您可以运行以下命令：

   ```
   $ deactivate
   ```

   有关更多信息，请参阅 [在 Device Farm 中自动运行 Appium 测试将 Appium 测试与 Device Farm 集成](test-types-appium.md)。

## APPIUM\$1PYTHON\$1TEST\$1PACKAGE\$1PYTEST\$1COLLECT\$1FAILED
<a name="APPIUM_PYTHON_TEST_PACKAGE_PYTEST_COLLECT_FAILED"></a>

如果您看到以下消息，请执行以下步骤来修复此问题。

**警告**  
我们未能在 tests 目录中收集测试。请解压缩您的测试程序包，通过运行命令 `py.test --collect-only <path to your tests directory>` 验证测试程序包是否有效，然后在该命令未输出任何错误后重试。

我们强烈建议您为包装测试设置 [Python virtualenv](https://pypi.python.org/pypi/virtualenv)。以下是使用 Python virtualenv 创建虚拟环境然后将其激活的示例流程：

```
$ virtualenv workspace
$ cd workspace 
$ source bin/activate
```

确保您可以解压测试程序包，而不会出现错误。在以下示例中，程序包的名称为 **test\$1bundle.zip**。

1. 将您的测试程序包复制到工作目录，然后运行以下命令：

   ```
   $ unzip test_bundle.zip
   ```

1. 要安装 wheel 文件，您可以运行以下命令：

   ```
   $ pip install --use-wheel --no-index --find-links=./wheelhouse --requirement=./requirements.txt
   ```

1. 要收集测试，您可以运行以下命令：

   ```
   $ py.test --collect-only tests
   ```

   有效的 Appium Python 程序包应生成类似以下内容的输出：

   ```
   ==================== test session starts ====================
   platform darwin -- Python 2.7.11, pytest-2.9.0, py-1.4.31, pluggy-0.3.1
   rootdir: /Users/zhena/Desktop/Ios/tests, inifile:
   collected 1 items
   <Module 'test_unittest.py'>
     <UnitTestCase 'DeviceFarmAppiumWebTests'>
       <TestCaseFunction 'test_devicefarm'>
   
   ==================== no tests ran in 0.11 seconds ====================
   ```

1. 要停用虚拟环境，您可以运行以下命令：

   ```
   $ deactivate
   ```

   有关更多信息，请参阅 [在 Device Farm 中自动运行 Appium 测试将 Appium 测试与 Device Farm 集成](test-types-appium.md)。

## APPIUM\$1PYTHON\$1TEST\$1PACKAGE\$1DEPENDENCY\$1WHEELS\$1INSUFFICIENT
<a name="APPIUM_PYTHON_TEST_PACKAGE_DEPENDENCY_WHEELS_INSUFFICIENT"></a>

如果您看到以下消息，请执行以下步骤来修复此问题。

**警告**  
我们无法在 wheelhouse 目录中找到足够的 wheel 依赖项。请解压缩您的测试包，然后打开 wheelhouse 目录。确认您已在 requirements.txt 文件中指定了所有 wheel 依赖项。

确保您可以解压测试程序包，而不会出现错误。在以下示例中，程序包的名称为 **test\$1bundle.zip**。

1. 将您的测试程序包复制到工作目录，然后运行以下命令：

   ```
   $ unzip test_bundle.zip
   ```

1. 检查 *requirements.txt* 文件的长度以及 wheelhouse 目录中 *.whl* 依赖文件的数量：

   ```
   $ cat requirements.txt | egrep "." |wc -l
   ﻿    12
   $ ls wheelhouse/ | egrep ".+\.whl" | wc -l
       11
   ```

   如果 *.whl* 依赖文件的数量小于 *requirements.txt* 文件中的非空行数，则需要确保以下几点：
   + *requirements.txt* 文件中的每一行都有一个与 *.whl* 相关的文件。
   + *requirements.txt* 文件中没有其他行包含依赖项包名称以外的信息。
   + *requirements.txt* 文件中没有在多行中重复依赖项名称，因此该文件中的两行可能对应于一个 *.whl* 依赖文件。

   AWS Device Farm 不支持 *requirements.txt* 文件中与依赖项包不直接对应的行，例如为`pip install` 命令指定全局选项的行。有关全局选项的列表，请参阅[要求文件格式](https://pip.pypa.io/en/stable/reference/requirements-file-format/#global-options)。

   有关更多信息，请参阅 [在 Device Farm 中自动运行 Appium 测试将 Appium 测试与 Device Farm 集成](test-types-appium.md)。