[thermalctld] Refactor to allow for greater unit test coverage; Add more unit tests#157
[thermalctld] Refactor to allow for greater unit test coverage; Add more unit tests#157jleveque merged 43 commits intosonic-net:masterfrom jleveque:increase_thermalctld_coverage
Conversation
… testing purposes
|
|
||
| fan_updater.log_warning.assert_called_with("Failed to update fan status - Failed to get speed") | ||
| # TODO: Clean this up once we no longer need to support Python 2 | ||
| if sys.version_info.major == 3: |
There was a problem hiding this comment.
How about we add a helper function like below:
def get_exception_message(msg):
if sys.version_info.major == 3:
return 'Exception(\'{},\')'.format(msg)
else:
return 'Exception(\'{}\')'.format(msg)And we don't have to change everywhere when removing python2 support.
There was a problem hiding this comment.
Thank you for the suggestion. However, I believe this unit test code will not change much, if at all before we remove Python 2 support. And with things the way they are, all we have to do is delete lines. If we make the change you suggested, there will actually be a bit more work needed when removing Python 2 support. Therefore, I prefer we just leave things as-is for the time being.
| 'pytest', | ||
| 'pytest-cov' | ||
| 'pytest-cov', | ||
| 'sonic-platform-common' |
There was a problem hiding this comment.
@jleveque this dependency is causing sonic-net/sonic-buildimage#7143 sonic-buildimage to fail.
Do we need to remove it or add something ?
There was a problem hiding this comment.
PR to add dependency in sonic-buildimage here
Unit tests for thermalctld depend on sonic-platform-common as of sonic-net/sonic-platform-daemons#157
Unit tests for thermalctld depend on sonic-platform-common as of sonic-net/sonic-platform-daemons#157
Unit tests for thermalctld depend on sonic-platform-common as of sonic-net/sonic-platform-daemons#157
Unit tests for thermalctld depend on sonic-platform-common as of sonic-net/sonic-platform-daemons#157
- Make `_read_eeprom_specific_bytes` Python3 and Python2 compatible - Change a stray `self.eep_dict.iteritems()` call to `self.eep_dict.items()`
Description
Refactor thermalctld to reduce the amount of code in infinite loops, thus allowing us better unit test coverage
Refactor mock_platform.py such that it inherits from sonic-platform-common in order to ensure it is aligned with the current API definitions (this introduces a test-time dependency on the sonic-platform-common package)
Eliminate the need to check for a
THERMALCTLD_UNIT_TESTINGenvironment variable in daemon codeIncrease pytest verbosity to prevent truncation of error messages
Miscellaneous cleanup:
Increase overall unit test unit test coverage from 73% to 93%
Previous unit test coverage:
Unit test coverage with this patch:
Motivation and Context
As part of ongoing efforts to increase unit test coverage >= 90% across the SONiC codebase in order to prevent regressions
How Has This Been Tested?
The refactored thermalctld has been tested on a physical DUT and the unit test results can be examined via the Azure Pipelines check builds in this PR.