代码之家  ›  专栏  ›  技术社区  ›  Ganesh Satpute

如何排除Python多模块覆盖范围内的目录

  •  0
  • Ganesh Satpute  · 技术社区  · 5 年前

    ProjectRoot
        - Module1
            src/
            tests/
        - Module2
            src/
            tests/
        ...
    

    我想从根目录运行所有测试并计算覆盖率。这是我正在使用的命令

    python -m coverage run --branch -m unittest **/tests/test*

    在这里,我想排除某些目录。我该怎么做?

    我尝试了一种方法 .coveragerc

    ...
    omit =
        Module2/*
    ...
    

    python -m coverage run --rcfile=.coveragerc --branch -m unittest **/tests/test*

    但它仍然试图获取模块2进行测试。

    0 回复  |  直到 5 年前
        1
  •  0
  •   Sosel    5 年前

    [report]
    exclude_lines =
        pragma: no cover
    
    include =
        ../toolbox/*.py
        ../geometry_finder/*.py
        ../position_optimiser/*.py
    
    [html]
    directory = c:\tmp\Report
    

    我现在尝试了以下方法:

    [report]
    exclude_lines =
        pragma: no cover
    
    include =
        ../.
    
    omit = 
        ../toolbox/*.py
    
    [html]
    directory = c:\tmp\Report
    

    ... 我没有看到工具箱的覆盖范围。所以我不能确定。代码的启动使用:

    coverage run --branch .\unittest_package.py
    coverage html