使用 Python 3.4 我正在解析从 MongoDB (3.0.2) 读取的文档 - 我执行各种测试并生成以下形式的 JSON/BSON:
{
'FixedH': False,
'Mstereo': True,
'RecMet': False,
'Sstereo': True,
'bond': False,
'charge': False,
'isotope': False,
'length': 223,
'nocomponents': 1,
'nolayers': 6,
'stereo': True
}
Run Code Online (Sandbox Code Playgroud)
如果我尝试将其写回 MongoDB(从 shell),我会收到以下错误:
ReferenceError: False is not defined at (shell):1:175
如果我手动转换我的布尔值 (False --> false) 以便它们都是小写的,错误就会消失并且文档被写入到 MongoDB 的集合中。
我猜我不是第一个遇到这个问题的人,但我找不到任何已发布的解决方法。我怎样才能解决这种区分大小写不匹配的问题?
我目前正在使用 python 3.5.1 和 3.6 以及最新版本的 pytest。当使用参数化测试运行 pytest 时,我希望任何失败的测试仅显示失败的测试,而不是参数化测试的所有设置。
解释...
我使用 @pytest.mark.parametrize 装饰器编写了许多测试,以允许我使用许多不同的输入运行测试。
我还为参数化参数传递了一个 id 列表,如下例所示:
@pytest.mark.parametrize('input_name12, output_name12',
[
('chloroform', None),
('chloroform-d', (['deuterated'], '-d'))]
],
ids=[
"unlabelled chloroform",
"chloroform deuterio-labelled with -d"
]
def test_isotope_extract(input_name12, output_name12):
assert isotope_extract(input_name12) == output_name12
Run Code Online (Sandbox Code Playgroud)
在某些情况下,我想在测试中运行 10 多组参数。这通常工作正常。但是,当我运行测试时,如果一个或多个参数化测试失败,则每次失败时,所有参数化测试的整个块都会输出到终端。即,上述代码中的一项测试失败将导致该块中的所有代码以及断言失败的具体细节显示在终端中。
有没有什么方法可以抑制整个参数化测试的显示,这样当我失败时我只能看到失败的断言和关联的 Id?