diff --git a/python_files/tests/pytestadapter/.data/coverage_w_config/pyproject.toml b/python_files/tests/pytestadapter/.data/coverage_w_config/pyproject.toml index 334fa05bd25e..c3406cc68929 100644 --- a/python_files/tests/pytestadapter/.data/coverage_w_config/pyproject.toml +++ b/python_files/tests/pytestadapter/.data/coverage_w_config/pyproject.toml @@ -2,4 +2,4 @@ # Licensed under the MIT License. [tool.coverage.report] -omit = ["test_ignore.py"] +omit = ["test_ignore.py", "tests/*.py"] diff --git a/python_files/tests/pytestadapter/.data/coverage_w_config/tests/test_disregard.py b/python_files/tests/pytestadapter/.data/coverage_w_config/tests/test_disregard.py new file mode 100644 index 000000000000..110a11534171 --- /dev/null +++ b/python_files/tests/pytestadapter/.data/coverage_w_config/tests/test_disregard.py @@ -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 diff --git a/python_files/tests/pytestadapter/test_coverage.py b/python_files/tests/pytestadapter/test_coverage.py index bbf5e2f83976..d0f802a23672 100644 --- a/python_files/tests/pytestadapter/test_coverage.py +++ b/python_files/tests/pytestadapter/test_coverage.py @@ -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) ] diff --git a/python_files/vscode_pytest/__init__.py b/python_files/vscode_pytest/__init__.py index 58d4b72fc46e..f7ba1d5842ef 100644 --- a/python_files/vscode_pytest/__init__.py +++ b/python_files/vscode_pytest/__init__.py @@ -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: