简体   繁体   English

针对不同语言版本运行代码覆盖是否有意义?

[英]Does it make sense to run code coverage against different language versions?

In a project I am involved with, our pipeline was designed to run coveralls in parallel on several different versions of python:在我参与的一个项目中,我们的管道旨在在 python 的几个不同版本上并行运行工作服:

Github Action yaml Github 动作 yaml

matrix:
        include:
          - python-version: 2.7
            tox-env: py27
          - python-version: 3.6
            tox-env: py36
          - python-version: 3.7
            tox-env: py37,docs,readme,black
          - python-version: 3.8
            tox-env: py38
          - python-version: 3.9
            tox-env: py39
          - python-version: pypy3
            tox-env: pypy3
...
    - name: Coverage format into lcov
      if: ${{ matrix.python-version != '2.7' }}
      run: |
        coverage-lcov --output_file_path lcov.info

I can appreciate why unit and functional tests would be run against several versions of the associated technology, however the code coverage, I can't truly come up with a good reason to keep running against all the different versions of python.我可以理解为什么要针对相关技术的多个版本运行单元和功能测试,但是代码覆盖率,我不能真正想出一个很好的理由来继续针对 python 的所有不同版本运行。 I am finding that running this against multiple versions doesn't reveal anything useful besides what appears to be small differences in relevant line calculations causing meaningless failures in the pipeline.我发现针对多个版本运行此程序并没有显示任何有用的信息,除了相关线路计算中的微小差异导致管道中的无意义故障之外。

Running coverallsapp(github actions) against 3.8 and greater, results in calculations that return more "relevant" lines than the same code against 3.7 and smaller.针对 3.8 及更高版本运行 coverallsapp(github 操作) 会导致计算返回比针对 3.7 及更低版本的相同代码更多的“相关”行。 This, I believe, is causing a pipeline failure due to a report of decreased code coverage of -0.0%, which after reviewing the actual reports in detail is a meaningless result.我相信,由于报告代码覆盖率降低了 -0.0%,这导致了管道故障,在详细查看实际报告之后,这是一个毫无意义的结果。

在此处输入图像描述

Just wanted to pose this question to determine if there was any real benefit to running the code coverage against so many versions of python.只是想提出这个问题,以确定对这么多版本的 python 运行代码覆盖是否有任何真正的好处。

No. In python I rarely, if ever, see code that branches on the python version, usually other techniques are used.没有。在 python 中,我很少(如果有的话)看到在 python 版本上分支的代码,通常使用其他技术。 Either way, coverage would be the same, eg无论哪种方式,覆盖范围都是相同的,例如

try:
   # do python 2 things
except:
   # do python 3 things instead.

You'd get about the same number of lines covered either way.无论哪种方式,您都会得到大约相同数量的行。 I think you've answered your own question in that in some later versions of python the error messages and metadata for tooling gets better for better reporting of a problem and where it happened.我认为您已经回答了您自己的问题,因为在 python 的某些更高版本中,工具的错误消息和元数据变得更好,可以更好地报告问题及其发生的位置。

Your project should state the versions of Python that you support and then test against those versions.您的项目应该state您支持的 Python 版本,然后针对这些版本进行测试

Advice: drop Python 2. That has been dead for more than two years.忠告:drop Python 2. 那已经死了两年多了。

For Python support all versions that still have support unless you require features that are only available in newer versions.对于 Python 支持所有仍具有支持的版本,除非您需要仅在较新版本中可用的功能。 That means dropping 3.6 and supporting 3.7, 3.8, 3.9, and 3.10.这意味着放弃 3.6 并支持 3.7、3.8、3.9 和 3.10。

However, I prefer to only support the last two released versions.但是,我更喜欢只支持最后两个发布的版本。 That is a decision for your project.这是您项目的决定。

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

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