python - 在 python 假设中禁用 NonInteractiveExampleWarning

标签 python hypothesis-test

我想使用hypothesis很棒的功能为我的应用程序创建一些示例数据。我大致是这样使用的

from hypothesis import strategies as st

ints = st.integers()  #simplified example
ints.example()

我收到此警告:

NonInteractiveExampleWarning: The .example() method is good for exploring strategies, but should only be used interactively

有没有简单的方法来禁用此警告?需要明确的是:我想在测试之外和非交互式上下文中使用示例数据生成,并且我知道警告所指的内容。我只是想摆脱它。

最佳答案

warnings模块允许您有选择地忽略特定警告;例如:

from hypothesis.errors import NonInteractiveExampleWarning
from hypothesis import strategies as st
import warnings

with warnings.catch_warnings():
    warnings.filterwarnings("ignore", category=NonInteractiveExampleWarning)

    ints = st.integers()
    print( ints.example() )

关于python - 在 python 假设中禁用 NonInteractiveExampleWarning,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73555634/

相关文章:

python - 如何在 Django 中使用 TailwindCSS?

python - python scipy.stats 中的 norm.ppf 与 norm.cdf

python - 我应该实例化多个测试使用的假设策略吗?

python - 为什么 SciPy 返回 `nan` 用于样本方差为 0 的 t 检验?

python - Python中有元组数据结构吗

python - 我无法减少从天花板上落下的雨滴数量

python - 在 matplotlib 中,如何绘制从轴向外指向的 R 样式轴刻度?

python - Hadoop流式传输命令失败

r - 对数据集中每一行的列进行 t.test

R:prop.test 根据传递给它的是矩阵还是向量返回不同的值