使用 CircleCI 进行测试时无法导入 unittest2

Unable to import unittest2 when testing with CircleCI

我正在尝试 运行 在 CircleCI 中进行一系列 python selenium 测试。 unittest2 是一项要求,位于 requirements.txt 文件中。 pip install -r requirements.txt 表明一切都已正确安装。

pip install -r requirements.txt
Requirement already satisfied: chromedriver==2.24.1 in /home/ubuntu/virtualenvs/venv-system/lib/python2.7/site-packages (from -r requirements.txt (line 1))
Requirement already satisfied: linecache2==1.0.0 in /home/ubuntu/virtualenvs/venv-system/lib/python2.7/site-packages (from -r requirements.txt (line 2))
Requirement already satisfied: nose==1.3.7 in /home/ubuntu/virtualenvs/venv-system/lib/python2.7/site-packages (from -r requirements.txt (line 3))
Requirement already satisfied: selenium==3.4.2 in /home/ubuntu/virtualenvs/venv-system/lib/python2.7/site-packages (from -r requirements.txt (line 4))
Requirement already satisfied: six==1.10.0 in /home/ubuntu/virtualenvs/venv-system/lib/python2.7/site-packages (from -r requirements.txt (line 5))
Requirement already satisfied: traceback2==1.4.0 in /home/ubuntu/virtualenvs/venv-system/lib/python2.7/site-packages (from -r requirements.txt (line 6))
Requirement already satisfied: unittest2==1.1.0 in /home/ubuntu/virtualenvs/venv-system/lib/python2.7/site-packages (from -r requirements.txt (line 7))
Requirement already satisfied: argparse in /usr/lib/python2.7 (from unittest2==1.1.0->-r requirements.txt (line 7))

然而,当运行测试脚本时,我得到

Traceback (most recent call last):
  File "checkpipinstallation.py", line 1, in <module>
    import unittest2
ImportError: No module named 'unittest2'
Traceback (most recent call last):
  File "main.py", line 2, in <module>
    import runner
  File "/home/ubuntu/ui-tests-functional/new_tests/runner.py", line 1, in <module>
    import unittest2
ImportError: No module named 'unittest2'

bash new_tests/circleSetUp.sh returned exit code 1

运行 来自 bash shell 安装 unittest2 的命令:

pip install unittest2
python3 checkpipinstallation.py
python3 main.py

checkpipinstallation.py只有一行:

import unittest2

来自 运行 宁 bash 脚本的输出:

Requirement already satisfied: unittest2 in /home/ubuntu/virtualenvs/venv-system/lib/python2.7/site-packages
Requirement already satisfied: argparse in /usr/lib/python2.7 (from unittest2)
Requirement already satisfied: six>=1.4 in /home/ubuntu/virtualenvs/venv-system/lib/python2.7/site-packages (from unittest2)
Requirement already satisfied: traceback2 in /home/ubuntu/virtualenvs/venv-system/lib/python2.7/site-packages (from unittest2)
Requirement already satisfied: linecache2 in /home/ubuntu/virtualenvs/venv-system/lib/python2.7/site-packages (from traceback2->unittest2)
Traceback (most recent call last):
  File "checkpipinstallation.py", line 1, in <module>
    import unittest2
ImportError: No module named 'unittest2'
Traceback (most recent call last):
  File "main.py", line 2, in <module>
    import runner
  File "/home/ubuntu/ui-tests-functional/new_tests/runner.py", line 1, in <module>
    import unittest2
ImportError: No module named 'unittest2'

bash new_tests/circleSetUp.sh returned exit code 1

您没有显示 Python 版本或 .circle.yml 所以我只能猜测:

pip install unittest2

使用 Python 2.7 安装 unittest2,而下一个命令使用 python3。尝试

pip3 install unittest2
pip3 install -r requirements.txt

要调试打印版本的内容:

python --version
python3 --version
pip --version
pip3 --version