[英]How do I make AWS Device Farm run Appium tests with python 3.x?
我正在尝试在 AWS Device Farm 上运行 python 3 中编写的 Appium 测试。 如文档中所述,
Python 2.7 在标准环境和使用自定义模式下均受支持。 当指定 Python 时,它是两者的默认值。
Python 3 仅在自定义模式下受支持。 要选择 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
# ...
我过去确实在 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
# ...
现在,当我运行测试时,我得到了这个日志,然后测试由于代码不兼容而崩溃。
[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)
python 3.x 是否不再受支持,或者是否有未记录的更改? 有没有在 python 3 环境中运行测试的新方法?
记录的方式仍然是正确的。
发现在虚拟环境下安装pytest package 时出现错误。 这使得py.test
命令引用默认环境。
在我的例子中,通过安装旧版本 pytest 并将其与其他软件包捆绑在 requirements.txt 中解决了这个问题。
pip install pytest==6.2.4
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.