Skip to content

Commit d7b9284

Browse files
authored
[thermalctld] Report unit test coverage (sonic-net#141)
Report Pytest unit test coverage for thermalctld. Current coverage: ``` ----------- coverage: platform linux, python 3.7.3-final-0 ----------- Name Stmts Miss Cover ----------------------------------------- scripts/thermalctld 424 113 73% Coverage HTML written to dir htmlcov Coverage XML written to file coverage.xml ``` - Also add check to import 'mock' from the 'unittest' package if running with Python 3
1 parent ad0a5ad commit d7b9284

3 files changed

Lines changed: 8 additions & 4 deletions

File tree

sonic-thermalctld/pytest.ini

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
[pytest]
2-
filterwarnings =
3-
ignore::DeprecationWarning
2+
addopts = --cov=scripts --cov-report html --cov-report term --cov-report xml

sonic-thermalctld/setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@
2121
'wheel'
2222
],
2323
tests_require=[
24+
'mock>=2.0.0; python_version < "3.3"',
2425
'pytest',
25-
'mock>=2.0.0'
26+
'pytest-cov'
2627
],
2728
classifiers=[
2829
'Development Status :: 4 - Beta',

sonic-thermalctld/tests/test_thermalctld.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22
import sys
33
from imp import load_source
44

5-
from mock import Mock, MagicMock, patch
5+
# TODO: Clean this up once we no longer need to support Python 2
6+
if sys.version_info.major == 3:
7+
from unittest.mock import Mock, MagicMock, patch
8+
else:
9+
from mock import Mock, MagicMock, patch
610
from sonic_py_common import daemon_base
711

812
from .mock_platform import MockChassis, MockFan, MockThermal

0 commit comments

Comments
 (0)