簡體   English   中英

如何讓 AWS Device Farm 使用 python 3.x 運行 Appium 測試?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM