Python/Pandas:带假设的单元测试 - 重现伪造的例子
Python/Pandas: Unit testing with hypothesis - reproducing falsifying example
使用 hypothesis
库进行单元测试,我想知道如何重现伪造的示例 pd.DataFrame
?
输出如下所示:
Falsifying example: test_data_frame_data(
data= sec_1 sec_2 sec_3
2020-01-01 00:00:00.000001 0.0 -0.0 0.0
2020-01-01 00:00:00.000000 0.0 -0.0 0.0
2020-01-01 00:00:00.000257 0.0 -0.0 0.0
2020-01-01 00:00:00.000258 0.0 -0.0 0.0
2020-01-01 00:00:00.000261 0.0 -0.0 0.0
... ... ... ...
2020-01-01 00:00:01.526858 0.0 -0.0 0.0
2020-01-01 01:00:01.065796 0.0 -0.0 0.0
2020-01-01 01:00:01.065797 0.0 -0.0 0.0
2020-01-01 01:01:01.065795 0.0 -0.0 0.0
2020-01-01 00:01:01.000020 0.0 -0.0 0.0
[300 rows x 3 columns],
)
Hypothesis
没有打印 seed
或 @reproduce_failure
的提示。
我只是想使用伪造的例子来调试我的代码。
我在假设 GitHub 问题页面 (https://github.com/HypothesisWorks/hypothesis/issues/2584) 上得到了提示。感谢@Zac-HD.
第一个解决方案:
将 @settings(print_blob=True)
放在测试之前。这将确保您获得如何重现潜在错误的提示。
第二种解决方案:
注册设置配置文件(例如在您的 conftest.py
中):
from hypothesis import settings
settings.register_profile(name="dev", max_examples=20, print_blob=True)
关于settings
的一切都可以在官方文档中找到:https://hypothesis.readthedocs.io/en/latest/settings.html
使用 hypothesis
库进行单元测试,我想知道如何重现伪造的示例 pd.DataFrame
?
输出如下所示:
Falsifying example: test_data_frame_data(
data= sec_1 sec_2 sec_3
2020-01-01 00:00:00.000001 0.0 -0.0 0.0
2020-01-01 00:00:00.000000 0.0 -0.0 0.0
2020-01-01 00:00:00.000257 0.0 -0.0 0.0
2020-01-01 00:00:00.000258 0.0 -0.0 0.0
2020-01-01 00:00:00.000261 0.0 -0.0 0.0
... ... ... ...
2020-01-01 00:00:01.526858 0.0 -0.0 0.0
2020-01-01 01:00:01.065796 0.0 -0.0 0.0
2020-01-01 01:00:01.065797 0.0 -0.0 0.0
2020-01-01 01:01:01.065795 0.0 -0.0 0.0
2020-01-01 00:01:01.000020 0.0 -0.0 0.0
[300 rows x 3 columns],
)
Hypothesis
没有打印 seed
或 @reproduce_failure
的提示。
我只是想使用伪造的例子来调试我的代码。
我在假设 GitHub 问题页面 (https://github.com/HypothesisWorks/hypothesis/issues/2584) 上得到了提示。感谢@Zac-HD.
第一个解决方案:
将 @settings(print_blob=True)
放在测试之前。这将确保您获得如何重现潜在错误的提示。
第二种解决方案:
注册设置配置文件(例如在您的 conftest.py
中):
from hypothesis import settings
settings.register_profile(name="dev", max_examples=20, print_blob=True)
关于settings
的一切都可以在官方文档中找到:https://hypothesis.readthedocs.io/en/latest/settings.html