我想使用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/