diff --git a/requirements.txt b/requirements.txt index 3568c24..df8eb42 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,6 +4,8 @@ juju juju_wait PyYAML flake8>=2.2.4,<=3.5.0 +flake8-docstrings +flake8-per-file-ignores mock>=1.2 nose>=1.3.7 pbr>=1.8.0,<1.9.0 diff --git a/tox.ini b/tox.ini index 63f667d..ab70085 100644 --- a/tox.ini +++ b/tox.ini @@ -23,6 +23,8 @@ commands = {posargs} [flake8] ignore = E402,E226 +per-file-ignores = + unit_tests/**: D [testenv:docs] basepython = python3 diff --git a/unit_tests/utils.py b/unit_tests/utils.py index e1d0fb6..d774500 100644 --- a/unit_tests/utils.py +++ b/unit_tests/utils.py @@ -15,6 +15,8 @@ # sys.modules['charmhelpers.contrib.openstack.utils'] = mock.MagicMock() # sys.modules['charmhelpers.contrib.network.ip'] = mock.MagicMock() +"""Module to provide helper for writing unit tests.""" + import contextlib import io import mock @@ -23,10 +25,13 @@ import unittest @contextlib.contextmanager def patch_open(): - '''Patch open() to allow mocking both open() itself and the file that is + """Patch open(). + + Patch open() to allow mocking both open() itself and the file that is yielded. - Yields the mock for "open" and "file", respectively.''' + Yields the mock for "open" and "file", respectively. + """ mock_open = mock.MagicMock(spec=open) mock_file = mock.MagicMock(spec=io.FileIO) @@ -40,12 +45,19 @@ def patch_open(): class BaseTestCase(unittest.TestCase): + """Base class for creating classes of unit tests.""" + + def shortDescription(self): + """Disable reporting unit test doc strings rather than names.""" + return None def setUp(self): + """Run setup of patches.""" self._patches = {} self._patches_start = {} def tearDown(self): + """Run teardown of patches.""" for k, v in self._patches.items(): v.stop() setattr(self, k, None) @@ -54,6 +66,7 @@ class BaseTestCase(unittest.TestCase): def patch_object(self, obj, attr, return_value=None, name=None, new=None, **kwargs): + """Patch the given object.""" if name is None: name = attr if new is not None: @@ -68,6 +81,7 @@ class BaseTestCase(unittest.TestCase): setattr(self, name, started) def patch(self, item, return_value=None, name=None, new=None, **kwargs): + """Patch the given item.""" if name is None: raise RuntimeError("Must pass 'name' to .patch()") if new is not None: