1. Ned Batchelder
  2. coverage.py
  3. Issues
Issue #218 resolved

run command does not respect the --omit flag

Jonathan Suever
created an issue

When running coverage and specifying a source directory, if you would like to omit a submodule using the --omit flag, it is ignored by run.

If you add the omit definition to a configuration file under the [run] section, it appears that it respects it, however, it doesn't actually it's just that both REPORT and HTML read the omit definition of the [run] part of the configuration file.

If you remove the configuration file, then don't actually run coverage again, but rather just generate a report, you can see that the "omitted" folder was still processed.

I have attached an example module along with a bash script for demonstrating the issue (reproduce.sh). In this example, I am attempting to ignore test_module/contrib.

Comments (4)

  1. Ned Batchelder repo owner

    First, thanks for the great reproducible test case!

    Here's the output I got:

    ##################################################
    Running coverage without an OMIT flag
    ##################################################
    Name                           Stmts   Miss  Cover
    --------------------------------------------------
    test_module/__init__               1      0   100%
    test_module/contrib/__init__       0      0   100%
    test_module/test/__init__          0      0   100%
    test_module/test/run_tests         1      0   100%
    --------------------------------------------------
    TOTAL                              2      0   100%
    
    ##################################################
    Running coverage with an OMIT flag
    ##################################################
    Name                           Stmts   Miss  Cover
    --------------------------------------------------
    test_module/__init__               1      0   100%
    test_module/contrib/__init__       0      0   100%
    test_module/test/__init__          0      0   100%
    test_module/test/run_tests         1      0   100%
    --------------------------------------------------
    TOTAL                              2      0   100%
    
    ##################################################
    Creating .coveragerc file and specifying omit there
    ##################################################
    .coveragerc contents:
    [run]
    omit=
        test_module/contrib/*
    
    Name                         Stmts   Miss  Cover
    ------------------------------------------------
    test_module/__init__             1      0   100%
    test_module/test/__init__        0      0   100%
    test_module/test/run_tests       1      0   100%
    ------------------------------------------------
    TOTAL                            2      0   100%
    
    ##################################################
    Now removing .coveragerc file
    ##################################################
    Name                           Stmts   Miss  Cover
    --------------------------------------------------
    test_module/__init__               1      0   100%
    test_module/contrib/__init__       0      0   100%
    test_module/test/__init__          0      0   100%
    test_module/test/run_tests         1      0   100%
    --------------------------------------------------
    TOTAL                              2      0   100%
    

    Here's what's happening: test_module/contrib/init.py was never run. Because you specified source=test_module, when the execution was done, coverage.py searched the tree for unexecuted files, and found that file, and marked it as unexecuted in the results.

    BUG: the search for unexecuted files should take the "omit" setting into account, and not add them as unexecuted if they are omitted.

    I fiddled with the test case some, and added some more cases. I made test_module/contrib/init.py actually execute, and I added a run with no --source setting. I got this:

    ##################################################
    Running coverage without an OMIT flag
    ##################################################
    Name                           Stmts   Miss  Cover
    --------------------------------------------------
    test_module/__init__               1      0   100%
    test_module/contrib/__init__       1      0   100%
    test_module/test/__init__          0      0   100%
    test_module/test/run_tests         2      0   100%
    --------------------------------------------------
    TOTAL                              4      0   100%
    
    ##################################################
    Running coverage with an OMIT flag
    ##################################################
    Name                           Stmts   Miss  Cover
    --------------------------------------------------
    test_module/__init__               1      0   100%
    test_module/contrib/__init__       1      1     0%
    test_module/test/__init__          0      0   100%
    test_module/test/run_tests         2      0   100%
    --------------------------------------------------
    TOTAL                              4      1    75%
    
    ##################################################
    Running coverage with an OMIT flag and no SOURCE
    ##################################################
    Name                         Stmts   Miss  Cover
    ------------------------------------------------
    test_module/__init__             1      0   100%
    test_module/test/run_tests       2      0   100%
    ------------------------------------------------
    TOTAL                            3      0   100%
    
    ##################################################
    Creating .coveragerc file and specifying omit there
    ##################################################
    .coveragerc contents:
    [run]
    omit=
        test_module/contrib/*
    
    Name                         Stmts   Miss  Cover
    ------------------------------------------------
    test_module/__init__             1      0   100%
    test_module/test/__init__        0      0   100%
    test_module/test/run_tests       2      0   100%
    ------------------------------------------------
    TOTAL                            3      0   100%
    
    ##################################################
    Now removing .coveragerc file
    ##################################################
    Name                           Stmts   Miss  Cover
    --------------------------------------------------
    test_module/__init__               1      0   100%
    test_module/contrib/__init__       1      1     0%
    test_module/test/__init__          0      0   100%
    test_module/test/run_tests         2      0   100%
    --------------------------------------------------
    TOTAL                              4      1    75%
    

    Notice in the first case (no omit), the file is marked as 100%. In the second case (omit), it's marked as 0%! Keep in mind, the file is fully run. In this second case, it's because the actual execution is ignored because of the omit, but then the file is found during the search for unexecuted files, and added in as unexecuted.

    In the third case (omit, but no source), the file is completed left out of the report, as you'd expect.

    Thanks for the report, and sorry for the delay in digging into it!

  2. Log in to comment