简体   繁体   English

如何针对不同版本的python运行py.test?

[英]How to run py.test against different versions of python?

是否可以在没有插件(如xdist )或tox情况下使用不同版本的python运行py.test

The simplest way to do it is by running the pytest module directly with -m , for example: 最简单的方法是使用-m直接运行pytest模块,例如:

python2.6 -m pytest

Note that you have to have pytest installed for that version of Python. 请注意,您必须为该版本的Python安装pytest。 In addition, you need to install all pytest plugins that you are using for that version of Python too. 此外,您还需要安装所有用于该版本 Python的pytest插件。

You can create a standalone pytest script with 您可以使用创建独立的pytest脚本

py.test --genscript=mypytest

and then do 然后呢

pythonXY mypytest 

to run tests with a particular python version. 使用特定的python版本运行测试。

You do not need to install pytest for that particular python version as pytest is completely contained in the "mypytest" script. 你不需要为那个特定的python版本安装pytest,因为pytest完全包含在“mypytest”脚本中。

VirtualEnv is done to handle those case. 完成VirtualEnv来处理这些情况。

virtualenv is a tool to create isolated Python environments. virtualenv是一个创建孤立的Python环境的工具。

Using virtualenv, you will be able to create multiple environements, each one with one plugin you want. 使用virtualenv,您将能够创建多个环境,每个环境都有一个您想要的插件。

Using xdist plugin this can be easily done : 使用xdist插件可以轻松完成

py.test -d --tx popen//python=pythonX

runs python version X (2 or 3). 运行python版本X(2或3)。


Since this is the first google result of "pytest test multiple versions" I'm posting this, nevertheless I realize this is not an answer to OP's question of how to do this without plugins. 由于这是"pytest test multiple versions"的第一个谷歌结果,我发布了这个,但我意识到这不是OP的问题,如何在没有插件的情况下做到这一点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM