[New-bugs-announce] [issue30181] Incorrect parsing of test case docstring

Ben Finney report at bugs.python.org
Wed Apr 26 22:44:34 EDT 2017


New submission from Ben Finney:

The docstring of a test case is not correctly parsed for display.

The attached ‘test_foo.py’ module contains two test case functions. Both docstrings conform to PEP 257 <https://www.python.org/dev/peps/pep-0257/>: they have a single-line synopsis and some extra text in a new paragraph.

However, only one of the functions has its docstring synopsis used in the output:

=====
======================================================================
FAIL: test_lower_returns_expected_code (test_foo.Foo_TestCase)
Should return expected code.
----------------------------------------------------------------------
Traceback (most recent call last):
[…]

======================================================================
FAIL: test_reverse_returns_expected_text (test_foo.Foo_TestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
[…]

----------------------------------------------------------------------
Ran 2 tests in 0.001s
=====

This violates the docstring parsing as described in PEP 257. The synopsis should be obtained by, first, stripping leading and trailing whitespace from the docstring; then, from that stripped text, taking the first line as the synopsis.

So the expected output for ‘test_foo.Foo_TestCase. test_reverse_returns_expected_text’ should include its docstring synopsis, “Should return expected reverse text.”

----------
components: Library (Lib)
files: test_foo.py
messages: 292387
nosy: benf_wspdigital
priority: normal
severity: normal
status: open
title: Incorrect parsing of test case docstring
type: behavior
versions: Python 2.7, Python 3.3, Python 3.4, Python 3.5, Python 3.6, Python 3.7
Added file: http://bugs.python.org/file46831/test_foo.py

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue30181>
_______________________________________


More information about the New-bugs-announce mailing list