【问题标题】:How to see the "Bundle" output of Hypothesis Python library? (Stateful testing)如何查看 Hypothesis Python 库的“Bundle”输出? (有状态测试)
【发布时间】:2020-01-17 06:20:53
【问题描述】:

在使用假设库并执行状态测试时,我如何查看或输出该库在我的代码上尝试的捆绑“服务”?

例子

import hypothesis.strategies as st
from hypothesis.strategies import integers
from hypothesis.stateful import Bundle, RuleBasedStateMachine, rule, precondition

class test_servicediscovery(RuleBasedStateMachine):
    services = Bundle('services')    
    @rule(target=services, s=st.integers(min_value=0, max_value=2)) 
    def add_service(self, s):
        return s

问题是:如何打印/查看库生成的 Bundle“服务”变量?

【问题讨论】:

    标签: python testing stateful python-hypothesis


    【解决方案1】:

    在您给出的示例中,services 包没有在您的代码上进行尝试 - 您正在向其中添加内容,但从不将它们用作其他规则的输入。

    如果是,在详细模式下运行 Hypothesis 将在所有输入发生时显示它们;甚至在正常模式下失败的例子都会打印出所有使用的值。

    【讨论】:

    • 感谢您的回答。我在另一个规则中使用捆绑包。我没有把它放出来,因为我只想展示我在代码中使用的包。 test_servicediscovery 的每个实例是否都有自己的捆绑包?
    • 我可以看到失败的示例,并且在调试模式下,我可以看到假设一直在尝试的示例。但我想知道捆绑包是被视为类变量还是实例变量。这就是我需要打印一个包或查看它在每个示例运行期间的样子的原因。
    • 是的,它更像是一个实例变量。虽然打印它不太可能有用......
    猜你喜欢
    • 2011-07-24
    • 1970-01-01
    • 2023-02-06
    • 2018-10-12
    • 2019-06-16
    • 1970-01-01
    • 2010-11-17
    • 1970-01-01
    相关资源
    最近更新 更多