Python doctest 异常

标签 python exception python-2.7 python-3.x doctest

因此,我正在尝试将异常与 doctest 匹配。

>>> api = Api("foo", "bar") # doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
...
AuthError

问题是这适用于 py2.7 但不适用于 python 3。异常跟踪的格式已更改,因此现在它包含完整的模块名称。 IE。在 python 3 中,我有 package.module.AuthError

有没有办法使两者都匹配?似乎 IGNORE_EXCEPTION_DETAIL 在这里没有效果。

最佳答案

这被相关问题的补丁无意中破坏了:IGNORE_EXCEPTION_DETAIL should ignore the module name

您看到的意外行为是一个悬而未决的问题:doctest.IGNORE_EXCEPTION_DETAIL doesn't match when no detail exists

据我所知,这是一个错误。这是很好的保证它得到修复,因为我写了doctest开始;-)与此同时,您可能想尝试附加到第二个错误的补丁报告。

跟进:昨晚我 checkin 了一个修复程序,它将出现在 Python 2.7、3.3 和 3.4 的下一版本中。感谢您的插入:-)

关于Python doctest 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20360457/

相关文章:

python - Python 中的 %i 和 %d 有什么区别?

Python dict.get() 引发 KeyError

python - 对 Python 中 Pandas 的多列 groupby 操作的含义感到困惑

python - 在 PIL 中旋转一个正方形

python - 在 matplotlib 中添加颜色条时出现 AttributeError

java - 如何避免打印异常并在遇到异常时分配另一个操作?我的尝试不成功

php - 如何捕获需要错误 + error_handlers

ios - Swift 中的“NSInternalInconsistencyException”

python - Django 获取 ImageField 路径

python - 类型错误 : unbound method decode() must be called with JSONDecoder instance as first argument (got PrintJson instance instead)