Skip to content

Commit 2431d71

Browse files
authored
PYTHON-3987 Enable coverage relative_files=true and use pyproject.toml (#1406)
1 parent 650cde9 commit 2431d71

File tree

4 files changed

+26
-27
lines changed

4 files changed

+26
-27
lines changed

.coveragerc

Lines changed: 0 additions & 25 deletions
This file was deleted.

.evergreen/combine-coverage.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ fi
1414

1515
createvirtualenv "$PYTHON_BINARY" covenv
1616
# coverage 7.3 dropped support for Python 3.7, keep in sync with run-tests.sh
17-
pip install -q "coverage<7.3"
17+
# coverage >=5 is needed for relative_files=true.
18+
pip install -q "coverage>=5,<7.3"
1819

1920
pip list
2021
ls -la coverage/

.evergreen/run-tests.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,8 @@ python -c 'import sys; print(sys.version)'
259259
PYTHON_IMPL=$($PYTHON -c "import platform; print(platform.python_implementation())")
260260
if [ -n "$COVERAGE" ] && [ "$PYTHON_IMPL" = "CPython" ]; then
261261
# coverage 7.3 dropped support for Python 3.7, keep in sync with combine-coverage.sh.
262-
python -m pip install pytest-cov "coverage<7.3"
262+
# coverage >=5 is needed for relative_files=true.
263+
python -m pip install pytest-cov "coverage>=5,<7.3"
263264
TEST_ARGS="$TEST_ARGS --cov pymongo --cov-branch --cov-report term-missing:skip-covered"
264265
fi
265266

pyproject.toml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,3 +163,25 @@ dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?)|dummy.*)$"
163163
"RET", "ARG", "F405", "B028", "PGH001", "B018", "F403", "RUF015", "E731", "B007",
164164
"UP031", "F401", "B023", "F811"]
165165
"green_framework_test.py" = ["T201"]
166+
167+
[tool.coverage.run]
168+
branch = true
169+
source = ["pymongo", "bson", "gridfs" ]
170+
relative_files = true
171+
172+
[tool.coverage.report]
173+
exclude_lines = [
174+
"if (.*and +)*_use_c( and.*)*:",
175+
"def has_c",
176+
"def get_version_string",
177+
"^except AttributeError:",
178+
"except ImportError:",
179+
"raise NotImplementedError",
180+
"return NotImplemented",
181+
"_use_c = true",
182+
"if __name__ == '__main__':",
183+
]
184+
partial_branches = ["if (.*and +)*not _use_c( and.*)*:"]
185+
186+
[tool.coverage.html]
187+
directory = "htmlcov"

0 commit comments

Comments
 (0)