From 1b0bbb9a560fea11f71f567384ffd52375d4ef7c Mon Sep 17 00:00:00 2001 From: Athanasius Date: Fri, 30 Sep 2022 19:25:22 +0100 Subject: [PATCH] tests: Improved coverage reporting * Always report on coverage, if no tests failed. * Remove `.coveragerc`, in favour of `pyproject.toml`. * Use `coverage-conditional-plugin`: - Two rules added, `sys-platform-win32` and `sys-platform-not-win32`. - Those rules used so non-win32 code run on win32 doesn't cause coverage to be reported as less than 100%. There's the assumption that !win32 means Linux, probably. --- .coveragerc | 6 ------ journal_lock.py | 8 ++++---- pyproject.toml | 9 ++++++++- requirements-dev.txt | 1 + 4 files changed, 13 insertions(+), 11 deletions(-) delete mode 100644 .coveragerc diff --git a/.coveragerc b/.coveragerc deleted file mode 100644 index 019facb4..00000000 --- a/.coveragerc +++ /dev/null @@ -1,6 +0,0 @@ -[run] -omit = - # The tests themselves - tests/* - # Any venv files - venv/* diff --git a/journal_lock.py b/journal_lock.py index 91a7895f..b96fd9e9 100644 --- a/journal_lock.py +++ b/journal_lock.py @@ -94,7 +94,7 @@ class JournalLock: :return: LockResult - See the class Enum definition """ - if sys.platform == 'win32': + if sys.platform == 'win32': # pragma: sys-platform-not-win32 logger.trace_if('journal-lock', 'win32, using msvcrt') # win32 doesn't have fcntl, so we have to use msvcrt import msvcrt @@ -107,7 +107,7 @@ class JournalLock: f", assuming another process running: {e!r}") return JournalLockResult.ALREADY_LOCKED - else: # pytest coverage only sees this on !win32 + else: # pragma: sys-platform-win32 logger.trace_if('journal-lock', 'NOT win32, using fcntl') try: import fcntl @@ -143,7 +143,7 @@ class JournalLock: return True # We weren't locked, and still aren't unlocked = False - if sys.platform == 'win32': + if sys.platform == 'win32': # pragma: sys-platform-not-win32 logger.trace_if('journal-lock', 'win32, using msvcrt') # win32 doesn't have fcntl, so we have to use msvcrt import msvcrt @@ -160,7 +160,7 @@ class JournalLock: else: unlocked = True - else: # pytest coverage only sees this on !win32 + else: # pragma: sys-platform-win32 logger.trace_if('journal-lock', 'NOT win32, using fcntl') try: import fcntl diff --git a/pyproject.toml b/pyproject.toml index a7f41ad4..387f00c7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -7,9 +7,16 @@ line_length = 119 [tool.pytest.ini_options] testpaths = ["tests"] # Search for tests in tests/ +addopts = "--cov . --cov plugins --cov-report=term-missing --no-cov-on-fail" +# --cov-fail-under 80" [tool.coverage.run] -omit = ["venv/*"] # when running pytest --cov, dont report coverage in venv directories +omit = [ "tests/*", "venv/*", "dist.win32/*" ] +plugins = [ "coverage_conditional_plugin" ] + +[tool.coverage.coverage_conditional_plugin.rules] +sys-platform-win32 = "sys_platform == 'win32'" +sys-platform-not-win32 = "sys_platform != 'win32'" [tool.pyright] # pythonPlatform = 'Darwin' diff --git a/requirements-dev.txt b/requirements-dev.txt index a9f569f5..2ae38e0a 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -43,6 +43,7 @@ py2exe==0.12.0.1; sys_platform == 'win32' pytest==7.1.3 pytest-cov==4.0.0 # Pytest code coverage support coverage[toml]==6.5.0 # pytest-cov dep. This is here to ensure that it includes TOML support for pyproject.toml configs +coverage-conditional-plugin==0.7.0 # For manipulating folder permissions and the like. pywin32==304; sys_platform == 'win32'