Skip to content

Commit 9466391

Browse files
authored
add omit coverage support for path patterns (#24599)
fixes #24366
1 parent f0bdf82 commit 9466391

File tree

4 files changed

+14
-6
lines changed

4 files changed

+14
-6
lines changed

python_files/tests/pytestadapter/.data/coverage_w_config/pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
# Licensed under the MIT License.
33

44
[tool.coverage.report]
5-
omit = ["test_ignore.py"]
5+
omit = ["test_ignore.py", "tests/*.py"]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
3+
4+
def test_i_hope_this_is_ignored():
5+
assert True

python_files/tests/pytestadapter/test_coverage.py

+3
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,14 @@ def test_coverage_w_omit_config():
101101
│ ├── test_ignore.py
102102
│ ├── test_ran.py
103103
│ └── pyproject.toml
104+
│ ├── tests
105+
│ │ └── test_disregard.py
104106
105107
pyproject.toml file with the following content:
106108
[tool.coverage.report]
107109
omit = [
108110
"test_ignore.py",
111+
"tests/*.py" (this will ignore the coverage in the file tests/test_disregard.py)
109112
]
110113
111114

python_files/vscode_pytest/__init__.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -453,11 +453,11 @@ def pytest_sessionfinish(session, exitstatus):
453453
# remove files omitted per coverage report config if any
454454
omit_files = cov.config.report_omit
455455
if omit_files:
456-
omit_files = set(omit_files)
457-
# convert to absolute paths, check against file set
458-
omit_files = {os.fspath(pathlib.Path(file).absolute()) for file in omit_files}
459-
print("Files to omit from reporting", omit_files)
460-
file_set = file_set - omit_files
456+
print("Plugin info[vscode-pytest]: Omit files/rules: ", omit_files)
457+
for pattern in omit_files:
458+
for file in list(file_set):
459+
if pathlib.Path(file).match(pattern):
460+
file_set.remove(file)
461461

462462
for file in file_set:
463463
try:

0 commit comments

Comments
 (0)