doctest中的行太长

问题描述 投票:0回答:1

我正在用Python编写一个模拟数字类型的类。我希望有许多文档测试,也没有来自pylava的pycodestyle警告。

这是我的困难。

对于以下doctest

        Traceback (most recent call last):
            ...
        TypeError: Only RiemannSphere, integers or floats can be added to a RiemannSphere

我从pylava收到警告,因为我的行TypeError: ...太长。

即使有人在文档测试中,有人知道如何将其分为两行吗?

谢谢,

python-3.x doctest pylama
1个回答
0
投票

我刚刚使用ELLIPSIS找到了一个不错的解决方案:

最初的文档测试是:

        >>> 1j / z1
        Traceback (most recent call last):
            ...
        TypeError: Only RiemannSphere, integers or floats can be added to a RiemannSphere

使用# doctest: +ELLIPSIS directive,可以很快写成:

        >>> 1j / z1
        ... # doctest: +ELLIPSIS
        Traceback (most recent call last):
            ...
        TypeError: Only a RiemannSphere, ... divided by a RiemannSphere number

因此,现在很容易在Traceback中更改消息,以便pylava不发出警告。

© www.soinside.com 2019 - 2024. All rights reserved.