[英]How to test a library against different Python *patch* versions?
对于针对 3.8.1 的检查之一(假设您的 python3.8 指向 3.8.2),您可以使用发现标志
tox --discover /path/to/python3.8.1 -e py38
如果您想定义一个始终使用 3.8.1 的环境,您可以通过定义一个新的 tox 环境并将basepython设置为python3.8.1
。
[testenv:py381]
basepython = python3.8.1
[testenv:py382]
basepython = python3.8.2
可能最不麻烦(但乏味)的方法是在监狱或虚拟机中按顺序安装不同版本的 Python,然后在其上测试您的代码。
如果您在类 UNIX 系统上从源代码安装 Python,您可以尝试使用不同的前缀(例如/opt/patch1
、 opt/patch2
等)并排安装它们,然后使用正确的 python明确地运行您的测试,例如/opt/patch1/bin/python3
。 一个警告; 在这种情况下,我不确定 Python 可执行文件是否会找到正确的共享库。
ms-windows 安装程序允许您选择安装位置。 如果您指示它不要将 Python 放在 PATH 中并且不设置文件关联等,那也可能有效。 您还必须使用完整路径显式调用正确的 Python。
我会去 Docker 并运行它的容器。
$ docker run -it --rm -w /opt -v "$PWD:/opt" python:3.4.2 python <script.py>
-it - interactive mode --rm - remove container after the run -w - working directory inside container -v - map directory $PWD from host to /opt inside container <container> - python:3.4.2 <command> - python script.py
您可以使用以下命令查看哪些图像可用:
$ curl -s https://registry.hub.docker.com/v1/repositories/python/tags | \
jq -r .[].name | grep "^[23][.0-9]*$" | sort -V
2
2.7
2.7.7
2.7.8
2.7.9
2.7.10
2.7.11
2.7.12
2.7.13
2.7.14
2.7.15
2.7.16
3
3.2
3.2.6
3.3
3.3.5
3.3.6
3.3.7
3.4
3.4.1
3.4.2
3.4.3
3.4.4
3.4.5
3.4.6
3.4.7
3.4.8
3.4.9
3.4.10
3.5
3.5.0
3.5.1
3.5.2
3.5.3
3.5.4
3.5.5
3.5.6
3.5.7
3.6
3.6.0
3.6.1
3.6.2
3.6.3
3.6.4
3.6.5
3.6.6
3.6.7
3.6.8
3.6.9
3.7
3.7.0
3.7.1
3.7.2
3.7.3
3.7.4
grep
过滤掉 beta 和 alpha 版本,所以如果你需要它们 - 只需删除 grep。
如果您需要列表中没有的 Python 版本,您可以使用自定义 Python 构建docker
镜像。
例如 Alpine linux(它真的很小) https://github.com/docker-library/python/blob/f82205cde8f0a5ffa276103a50d843edced67757/3.7/alpine3.10/Dockerfile
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.