我正在尝试向我的pytest套件添加一个测试,该测试将验证用于运行测试的python版本,如果版本低于3.8,则失败并停止测试。 我想让pytest始终运行此测试,而与在命令行上执行的任何“ -k”过滤无关。
作为参考,这是实际测试(对改进它的任何评论也将受到赞赏):
@pytest.mark.tryfirst
def test_python_version():
version = sys.version_info
if version.major < 3:
logging.error("python2 is not supported")
pytest.exit("Stopped testing")
elif version.minor < 8:
logging.warning("Use python 3.8 or higher for best results")
我该如何实现?
谢谢!