我正在尝试编写一个pytest插件来自定义特定异常的外观 - 更具体地说,模拟异常(预期被调用的方法没有被调用等),因为在这些异常的追溯中存在大量无用的噪声.
这是我到目前为止所做的,它有效,但非常黑客:
import pytest
import flexmock
@pytest.hookimpl()
def pytest_exception_interact(node, call, report):
exc_type = call.excinfo.type
if exc_type == flexmock.MethodCallError:
entry = report.longrepr.reprtraceback.reprentries[-1]
entry.style = 'short'
entry.lines = [entry.lines[-1]]
report.longrepr.reprtraceback.reprentries = [entry]
Run Code Online (Sandbox Code Playgroud)
我认为我正在hookimpl
使用简单的if语句检查异常类型.
我尝试report.longrepr
用一个简单的字符串替换,这也有效,但后来我失去了格式化(终端中的颜色).
作为我想缩短的输出类型的一个例子,这是一个模拟断言失败:
=================================== FAILURES ====================================
_______________________ test_session_calls_remote_client ________________________
def test_session_calls_remote_client():
remote_client = mock.Mock()
session = _make_session(remote_client)
session.connect()
remote_client.connect.assert_called_once_with()
session.run_action('asdf')
> remote_client.run_action.assert_called_once_with('asdff')
tests/unit/executor/remote_test.py:22:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ …
Run Code Online (Sandbox Code Playgroud) 我使用的是mod_pagespeed的Apache。由于某种原因,我无法弄清楚,mod_pagespeed认为图像比实际小得多,这意味着一旦图像按比例放大,它就会变得很模糊。
有问题的图像是CSS背景图像。
有没有一种方法可以禁用特定文件的mod_pagespeed图像压缩?
鉴于此计划:
class Obj:
def __init__(self, a, b):
self.a = a
self.b = b
def __hash__(self):
return hash((self.a, self.b))
class Collection:
def __init__(self):
self.objs = set()
def add(self, obj):
self.objs.add(obj)
def find(self, a, b):
objs = []
for obj in self.objs:
if obj.b == b and obj.a == a:
objs.append(obj)
return objs
def remove(self, a, b):
for obj in self.find(a, b):
print('removing', obj)
self.objs.remove(obj)
o1 = Obj('a1', 'b1')
o2 = Obj('a2', 'b2')
o3 = Obj('a3', 'b3')
o4 = Obj('a4', 'b4')
o5 …
Run Code Online (Sandbox Code Playgroud) 如果我的HTML是这样的:
<tbody id="hasil-pencarian">
<tr>
<td align="center">1</td>
<td>TMS/IT/06/001</td>
<td>Erika Julia Widiyanti</td>
<td>Marketing</td>
<td>14-06-2015 13:59</td>
<td>14-06-2015 14:00</td>
<td>Erika test 1</td>
<td id="action" class="center" width="10px">
<a class="btn btn-success">
</td>
</tr>
</tbody>
Run Code Online (Sandbox Code Playgroud)
我得到了上面的所有html:
var result = $("#hasil-pencarian").html();
Run Code Online (Sandbox Code Playgroud)
但是,如何在不使用<td>
with的情况下获取所有HTML id='action'
?有点困惑.任何帮助将非常感激.