Skip to content

Commit 17d17ca

Browse files
committed
Exclude top-level import statements from coverage
Since our tests are invoked after most Ramble modules are already initialized, import statements (and other ones like `def`, `class` etc.) are not counted by the coverage tool. One option could be to invoke `coverage run` instead of using `pytest-cov`, but that requires handling subprocess invocation and I couldn't get that to work nicely. It seems relatively harmless to exclude these import statements, as even if a file is completely excluded from a test run, the actual content would still show up as missing coverage.
1 parent a3a2b19 commit 17d17ca

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

pyproject.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,12 @@ exclude_lines = [
7777
'if 0:',
7878
'if False:',
7979
'if __name__ == .__main__.:',
80+
81+
# Ignore import statements:
82+
# Imports (and defs) are not counted due to coverage being run after
83+
# these modules are already initialized.
84+
'^import .*',
85+
'^from .* import .*',
8086
]
8187
ignore_errors = true
8288
include = [

0 commit comments

Comments
 (0)