diff --git a/test_tox_pyenv.py b/test_tox_pyenv.py index 738d9f5..c5f73ff 100644 --- a/test_tox_pyenv.py +++ b/test_tox_pyenv.py @@ -73,6 +73,13 @@ def test_logs_if_no_pyenv_binary(self): self.assertEqual(tox_pyenv.LOG.warning.call_args_list, expected_warn) +class TestToxPyenvLogger(unittest.TestCase): + + def test_has_nullhandler(self): + handlers = {str(type(handler)) for handler in tox_pyenv.LOG.handlers} + self.assertTrue(any('NullHandler' in h for h in handlers)) + + class TestThings(unittest.TestCase): def test_the_answer(self): diff --git a/tox_pyenv.py b/tox_pyenv.py index 31b40f2..7538f9e 100644 --- a/tox_pyenv.py +++ b/tox_pyenv.py @@ -49,6 +49,17 @@ def tox_get_python_executable(envconfig): LOG = logging.getLogger(__name__) +try: + # Python 2.7+ + NullHandler = logging.NullHandler +except AttributeError: + class NullHandler(logging.Handler): + """This handler does nothing.""" + def emit(self, record): + pass + +LOG.addHandler(NullHandler()) + class ToxPyenvException(Exception): @@ -66,7 +77,7 @@ class PyenvWhichFailed(ToxPyenvException): @tox_hookimpl -def tox_get_python_executable(envconfig): +def tox_get_python_executable(envconfig): # pylint: disable=R1710 """Return a python executable for the given python base name. The first plugin/hook which returns an executable path will determine it.