1
0
mirror of https://github.com/EDCD/EDMarketConnector.git synced 2025-05-29 14:49:29 +03:00

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.
This commit is contained in:
Athanasius 2022-09-30 19:25:22 +01:00
parent bacd2ef9c6
commit 1b0bbb9a56
No known key found for this signature in database
GPG Key ID: 8C392035DD80FD62
4 changed files with 13 additions and 11 deletions

View File

@ -1,6 +0,0 @@
[run]
omit =
# The tests themselves
tests/*
# Any venv files
venv/*

View File

@ -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

View File

@ -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'

View File

@ -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'