简体   繁体   English

如何让 AWS Device Farm 使用 python 3.x 运行 Appium 测试?

[英]How do I make AWS Device Farm run Appium tests with python 3.x?

I'm trying to run Appium tests written in python 3 on AWS Device Farm.我正在尝试在 AWS Device Farm 上运行 python 3 中编写的 Appium 测试。 As stated in the documentation ,文档中所述,

Python 2.7 is supported in both the standard environment and using Custom Mode. Python 2.7 在标准环境和使用自定义模式下均受支持。 It is the default in both when specifying Python.当指定 Python 时,它是两者的默认值。

Python 3 is only supported in Custom Mode. Python 3 仅在自定义模式下受支持。 To choose Python 3 as your python version, change the test spec to set the PYTHON_VERSION to 3, as shown here:要选择 Python 3 作为您的 python 版本,请更改测试规范以将 PYTHON_VERSION 设置为 3,如下所示:

phases:
  install:
    commands:
      # ...
      - export PYTHON_VERSION=3
      - export APPIUM_VERSION=1.14.2
      # Activate the Virtual Environment that Device Farm sets up for Python 3, then use Pip to install required packages.
      - cd $DEVICEFARM_TEST_PACKAGE_PATH
      - . bin/activate
      - pip install -r requirements.txt
      # ...

I did run tests successfully on Device Farm in the past, using a python 3 custom environment, with this spec file (I include the install phase only):我过去确实在 Device Farm 上成功运行过测试,使用 python 3 自定义环境,使用这个规范文件(我只包括安装阶段):

phases:
  install:
    commands:
      # Device Farm support two major versions of Python, each with one minor version: 2 (minor version 2.7), and 3 (minor version 3.7.4).
      # The default Python version is 2, but you can switch to 3 by setting the following variable to 3:
      - export PYTHON_VERSION=3

      # This command will install your dependencies and verify that they're using the proper versions that you specified in your requirements.txt file. Because Device Farm preconfigures your environment within a
      # Python Virtual Environment in its setup phase, you can use pip to install any Python packages just as you would locally.
      - cd $DEVICEFARM_TEST_PACKAGE_PATH
      - . bin/activate
      - pip install -r requirements.txt
  # ...

Now, when I run the tests, I get this log an then the test crashes due to incompatible code.现在,当我运行测试时,我得到了这个日志,然后测试由于代码不兼容而崩溃。

[DEVICEFARM] ########### Entering phase test ###########
 
[DeviceFarm] echo "Navigate to test package directory"
Navigate to test package directory
[DeviceFarm] cd $DEVICEFARM_TEST_PACKAGE_PATH
[DeviceFarm] echo "Start Appium Python test"
Start Appium Python test
[DeviceFarm] py.test tests/ --junit-xml $DEVICEFARM_LOG_DIR/junitreport.xml
============================= test session starts ==============================
platform linux2 -- Python 2.7.6, pytest-2.8.5, py-1.4.31, pluggy-0.3.1
rootdir: /tmp/scratchrPuGRa.scratch/test-packageM5E89M/tests, inifile: 
collected 0 items / 3 errors

==================================== ERRORS ====================================
____________________ ERROR collecting test_home_buttons.py _____________________
/usr/local/lib/python2.7/dist-packages/_pytest/python.py:610: in _importtestmodule
    mod = self.fspath.pyimport(ensuresyspath=importmode)

Is python 3.x not supported anymore, or have there been undocumented changes? python 3.x 是否不再受支持,或者是否有未记录的更改? Is there a new way to run tests in a python 3 environment?有没有在 python 3 环境中运行测试的新方法?

The documented way is still correct.记录的方式仍然是正确的。

I found there was an error during the installation of the pytest package in the virtual environment.发现在虚拟环境下安装pytest package 时出现错误。 This made the py.test command refer to the default environment.这使得py.test命令引用默认环境。

In my case the issue was resolved by installing an older version of pytest and bundling it in requirements.txt with other packages.在我的例子中,通过安装旧版本 pytest 并将其与其他软件包捆绑在 requirements.txt 中解决了这个问题。

pip install pytest==6.2.4

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM