diff options
Diffstat (limited to 'logilab/common/testlib.py')
-rw-r--r-- | logilab/common/testlib.py | 34 |
1 files changed, 12 insertions, 22 deletions
diff --git a/logilab/common/testlib.py b/logilab/common/testlib.py index f8401c4..fe5e3c4 100644 --- a/logilab/common/testlib.py +++ b/logilab/common/testlib.py @@ -46,25 +46,26 @@ __docformat__ = "restructuredtext en" from contextlib import contextmanager import sys -import os, os.path as osp -import re -import difflib +import os +import os.path as osp import tempfile -import math import warnings from shutil import rmtree -from operator import itemgetter from inspect import isgeneratorfunction from typing import Any, Iterator, Union, Optional, Callable, Dict, List, Tuple from mypy_extensions import NoReturn import builtins -import configparser +import doctest from logilab.common.deprecation import class_deprecated, deprecated import unittest as unittest_legacy +from functools import wraps + +from logilab.common.decorators import cached, classproperty + if not getattr(unittest_legacy, "__package__", None): try: import unittest2 as unittest @@ -77,12 +78,6 @@ else: import unittest as unittest # type: ignore from unittest import SkipTest -from functools import wraps - -from logilab.common.debugger import Debugger -from logilab.common.decorators import cached, classproperty -from logilab.common import textutils - __all__ = ["unittest_main", "find_tests", "nocoverage", "pause_trace"] @@ -176,7 +171,7 @@ def find_tests(testdir, prefixes=DEFAULT_PREFIXES, suffix=".py", excludes=(), re return tests -## PostMortem Debug facilities ##### +# PostMortem Debug facilities ##### def start_interactive_mode(result): """starts an interactive shell so that the user can inspect errors """ @@ -283,8 +278,6 @@ unittest_main = unittest.main class InnerTestSkipped(SkipTest): """raised when a test is skipped""" - pass - def parse_generative_args(params: Tuple[int, ...]) -> Tuple[Union[List[bool], List[int]], Dict]: args = [] @@ -416,7 +409,7 @@ class TestCase(unittest.TestCase): ) result.addSuccess(self) return False - except: + except Exception: result.addError(self, self.__exc_info()) return False return True @@ -513,7 +506,7 @@ class TestCase(unittest.TestCase): success = False except SkipTest as e: result.addSkip(self, e) - except: + except Exception: # if an error occurs between two yield result.addError(self, self.__exc_info()) success = False @@ -547,7 +540,7 @@ class TestCase(unittest.TestCase): except SkipTest as e: result.addSkip(self, e) return 0 - except: + except Exception: result.addError(self, self.__exc_info()) return 2 return 0 @@ -567,8 +560,6 @@ TestCase.assertItemsEqual = deprecated("assertItemsEqual is deprecated, use asse TestCase.assertItemsEqual ) -import doctest - class SkippedSuite(unittest.TestSuite): def test(self): @@ -658,12 +649,11 @@ class MockConnection: def close(self): """Mock close method""" - pass # mypy error: Name 'Mock' is not defined # dynamic class created by this class -def mock_object(**params: Any) -> "Mock": # type: ignore +def mock_object(**params: Any) -> "Mock": # type: ignore # noqa """creates an object using params to set attributes >>> option = mock_object(verbose=False, index=range(5)) >>> option.verbose |