--omit="./*.py" omits ALL python files, not only files at the top level · Issue #1407 · nedbat/coveragepy (original) (raw)

Describe the bug
My intent is to trace all python files under project root, excepting a couple directories and python files in the top level.

This is close to what I want, but contains python files at the top level:

coverage run --source=. --omit="tests/","tests_integ/" -m pytest

but these will omit ALL python files (CoverageWarning: No data was collected. (no-data-collected)):

coverage run --source=. --omit="tests/*,tests_integ/*,*.py" -m pytest
coverage run --source=. --omit="tests/*,tests_integ/*,./*.py" -m pytest
coverage run --source=. --omit='tests/*,tests_integ/*,*.py' -m pytest

To Reproduce
How can we reproduce the problem? Please be specific. Don't link to a failing CI job.

Minimal repro:

❯ tree -I "__*"
.
├── bar
│   └── bar.py
├── foo.py
└── tests
    └── test_baz.py

2 directories, 3 files
❯ bat foo.py bar/bar.py tests/test_baz.py
───────┬────────────────────────────────────
       │ File: foo.py   <EMPTY>
───────┴────────────────────────────────────
───────┬────────────────────────────────────
       │ File: bar/bar.py   <EMPTY>
───────┴────────────────────────────────────
───────┬────────────────────────────────────
       │ File: tests/test_baz.py
───────┼────────────────────────────────────
   1   │ def test_foo():
   2   │     assert True
───────┴────────────────────────────────────

Then compare coverage report after running the two different commands:

coverage run --source=. -m pytest # traces coverage for every file coverage run --source=. --omit="./*.py" -m pytest # no files traced

Answer the questions below:

  1. What version of Python are you using? 3.7.6
  2. What version of coverage.py shows the problem? The output of coverage debug sys is helpful. 6.4.1
  3. What versions of what packages do you have installed? The output of pip freeze is helpful.
  4. What code shows the problem? Give us a specific commit of a specific repo that we can check out. If you've already worked around the problem, please provide a commit before that fix.
  5. What commands did you run?

Expected behavior
I expected either *.py or ./*.py to only match python files at the top level. In minimal repro above, that means ./foo.py should have been omitted from coverage trace, but ./bar/bar.py should not.

Additional context
I've also tried "omitting on read" via coverage report --omit, but that has the same problem.