【发布时间】:2020-01-29 17:07:35
【问题描述】:
我有一个Python project,我使用tox 来运行基于pytest 的测试。我正在尝试将项目配置为在 CircleCI 上构建。
tox.ini 将 Python 3.6 和 3.7 都列为环境:
envlist = py{36,37,},coverage
我可以在使用 Python 3.7 版的 conda 虚拟环境中的本地计算机上成功运行 tox。
在 CircleCI 上,我使用的是标准 Python 虚拟环境,因为这是示例(“入门”)配置中提供的内容。当 tox 尝试创建 Python 3.6 环境时,tox 测试失败:
py36 create: /home/circleci/repo/.tox/py36
ERROR: InterpreterNotFound: python3.6
看来,当您使用这种虚拟环境时,tox 只能找到相同版本的解释器,而如果使用 conda 虚拟环境,它会以某种方式知道如何制作环境,只要它们是较低版本.至少对于我的情况(在 Python 3.7 conda 环境中运行的 tox 的 Python 3.6 和 3.7 环境),这可以正常工作。
我目前使用的 CircleCI 配置文件如下所示:
# Python CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-python/ for more details
#
version: 2
jobs:
build:
docker:
# specify the version you desire here
# CircleCI maintains a library of pre-built images
# documented at https://circleci.com/docs/2.0/circleci-images/
- image: circleci/python:3.7
working_directory: ~/repo
steps:
- checkout
# Download and cache dependencies
- restore_cache:
keys:
- v1-dependencies-{{ checksum "requirements.txt" }}
# fallback to using the latest cache if no exact match is found
- v1-dependencies-
- run:
name: install dependencies
command: |
python3 -m venv venv
. venv/bin/activate
pip install -e .
pip install tox
- save_cache:
paths:
- ./venv
key: v1-dependencies-{{ checksum "requirements.txt" }}
# run tests with tox
- run:
name: run tests
command: |
. venv/bin/activate
tox
- store_artifacts:
path: test-reports
destination: test-reports
在 CircleCI 上使用 tox 测试多个环境的最佳实践是什么?我应该在 CircleCI 中使用 conda 而不是 venv,如果是,我将如何添加它?或者有没有办法保留venv,也许通过修改它的环境创建命令?
编辑
我现在发现这并不特定于 CircleCI,因为我在 Travis CI 上运行此毒物时遇到了类似的错误。此外,我已经确认这可以使用在我的本地计算机上使用venv 创建的 Python 3.7 虚拟环境进行宣传,py36 和 py37 环境都可以成功运行。
【问题讨论】: