Skip to content

Commit

Permalink
add omit coverage support for path patterns
Browse files Browse the repository at this point in the history
  • Loading branch information
eleanorjboyd committed Dec 13, 2024
1 parent 567ca5a commit 7bd8922
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
# Licensed under the MIT License.

[tool.coverage.report]
omit = ["test_ignore.py"]
omit = ["test_ignore.py", "tests/*.py"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

def test_i_hope_this_is_ignored():
assert True
3 changes: 3 additions & 0 deletions python_files/tests/pytestadapter/test_coverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,14 @@ def test_coverage_w_omit_config():
│ ├── test_ignore.py
│ ├── test_ran.py
│ └── pyproject.toml
│ ├── tests
│ │ └── test_disregard.py
pyproject.toml file with the following content:
[tool.coverage.report]
omit = [
"test_ignore.py",
"tests/*.py" (this will ignore the coverage in the file tests/test_disregard.py)
]
Expand Down
10 changes: 5 additions & 5 deletions python_files/vscode_pytest/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,11 +453,11 @@ def pytest_sessionfinish(session, exitstatus):
# remove files omitted per coverage report config if any
omit_files = cov.config.report_omit
if omit_files:
omit_files = set(omit_files)
# convert to absolute paths, check against file set
omit_files = {os.fspath(pathlib.Path(file).absolute()) for file in omit_files}
print("Files to omit from reporting", omit_files)
file_set = file_set - omit_files
print("Plugin info[vscode-pytest]: Omit files/rules: ", omit_files)
for pattern in omit_files:
for file in list(file_set):
if pathlib.Path(file).match(pattern):
file_set.remove(file)

for file in file_set:
try:
Expand Down

0 comments on commit 7bd8922

Please sign in to comment.