I'm trying to keep my source code under the 80 character guideline width that PEP8 recommends, but can't figure out how to wrap my doctest which has results longer than 80 characters.
A noddy example:
def long_string(): """ Returns a string which is wider than the recommended PEP8 linewidth >>> print long_string() 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 """ return '0123456789' * 10
I've tried a couple of combinations, including using # doctest: +NORMALIZE_WHITESPACE
and trying to simply wrap the line with a newline.
When the tests include values that are likely to change in unpredictable ways, and where the actual value is not important to the test results, you can use the ELLIPSIS option to tell doctest to ignore portions of the verification value.
The Doctest Module finds patterns in the docstring that looks like interactive shell commands. The input and expected output are included in the docstring, then the doctest module uses this docstring for testing the processed output.
Introduction. Doctest is a simple but useful testing method for Python programs. Compared with unit test, doctest doesn't require an independent script to write test cases. Test cases can just be written in the doc information (contents within triple single/double quotes) of a Python function.
Just figured out:
def long_string(): """ Returns a string which is wider than the recommended PEP8 linewidth >>> print long_string() 01234567890123456789012345678901234567890123456789012345678901234567890\ 12345678901234567890123456789 """ return '0123456789' * 10
Hope that helps somebody else out.
As suggested by davitenio and qris, I would recommend using the #doctest: +ELLIPSIS
directive, like so.
>>> from test.test_ppp import MockForm >>> form = MockForm(mock_file='no-errors.xlsx') >>> form.get_languages(settings_default='English', survey_header= ... form.metadata['raw_data']['survey'][0]) #doctest: +ELLIPSIS ['Ateso', 'English', 'Luganda', ... 'Runyoro-Rutoro']
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With