PyTest弃用:“junit\u族默认值将更改为'xunit2'

2024-06-16 11:55:22 发布

您现在位置:Python中文网/ 问答频道 /正文

我在circleci收到来自管道的弃用警告

消息

/home/circleci/evobench/env/lib/python3.7/site-packages/_pytest/junitxml.py:436: PytestDeprecationWarning: The 'junit_family' default value will change to 'xunit2' in pytest 6.0.

命令

- run:
    name: Tests
    command: |
      . env/bin/activate
      mkdir test-reports
      python -m pytest --junitxml=test-reports/junit.xml

我应该如何修改命令以使用xunit? 是否可以使用消息中提到的默认工具? 我的意思是没有指定xunit或junit

这是完整的pipeline


Tags: test命令env消息警告home管道pytest
3条回答

有关从xunit1移动到xunit2的官方声明/文件,请阅读:docs.pytest.org

此外,如果您的项目包含pytest.ini文件,则可以直接从文件中设置junit\u系列用法,如:

# pytest.ini
[pytest]
minversion = 6.0
junit_family=xunit2
junit_suite_name = Pytest Tests
addopts = -ra -q -v -s  junitxml=path/to/pytest_results/pytest.xml

以这种方式运行您的命令

与xunit2

python -m pytest -o junit_family=xunit2 junitxml=test-reports/junit.xml

与xunit1

python -m pytest -o junit_family=xunit1 junitxml=test-reports/junit.xml

python -m pytest -o junit_family=legacy junitxml=test-reports/junit.xml

This here详细描述了更改:

The default value of junit_family option will change to xunit2 in pytest 6.0, given that this is the version supported by default in modern tools that manipulate this type of file.

In order to smooth the transition, pytest will issue a warning in case the junitxml option is given in the command line but junit_family is not explicitly configured in pytest.ini:

PytestDeprecationWarning: The `junit_family` default value will change to 'xunit2' in pytest 6.0.   Add `junit_family=legacy` to your

pytest.ini file to silence this warning and make your suite compatible.

In order to silence this warning, users just need to configure the junit_family option explicitly:

[pytest]
junit_family=legacy

在pytest.ini文件中添加以下行:

junit_family=legacy

如果要保留 junitxml选项的默认行为。也可以接受新版本xunit2,但不显式定义junit_族变量

从本质上讲,警告所说的是您在您的应用程序中提供了 junitxml选项

run           
  name: Tests

节未指定junit\u族变量。您需要开始显式定义它以删除警告或接受新的默认值

This thread goes into more details about where to find the .ini file for pytest.

相关问题 更多 >