标签:python-mock
-
无法捕获模拟异常,因为它不继承BaseException - python
我正在一个项目中,该项目涉及连接到远程服务器,等待响应,然后根据该响应执行操作。我们捕获了两个不同的异常,并且根据捕获的异常而表现不同。例如: def myMethod(address, timeout=20): try: response = requests.head(address, timeout=timeout) except requests.e […]
-
在python 3.5中模拟异步调用 - python
如何使用unittest.mock.patch模拟从一个本地协程到另一本地协程的异步调用? 我目前有一个很尴尬的解决方案: class CoroutineMock(MagicMock): def __await__(self, *args, **kwargs): future = Future() future.set_result(self) result […]
-
Python测试:将伪造的文件与模拟&io.StringIO一起使用 - python
我正在尝试测试在文件上运行的一些代码,但似乎无法理解如何使用mock和io.StringIO替换实际文件我的代码大致如下: class CheckConfig(object): def __init__(self, config): self.config = self._check_input_data(config) def _check_input_d […]
-
如何从模拟实例的方法引发异常? - python
我要测试的演示功能非常简单。 def is_email_deliverable(email): try: return external.verify(email) except Exception: logger.error("External failed failed") return False 此函数使用我要模拟的externa […]