This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Unittest - Return empty string instead of None object on shortDescription()
Type: behavior Stage: resolved
Components: Tests Versions: Python 3.5
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: r.david.murray, rhettinger, serhiy.storchaka, viniciusd
Priority: normal Keywords:

Created on 2017-03-01 16:21 by viniciusd, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 383 closed viniciusd, 2017-03-01 16:57
Messages (6)
msg288763 - (view) Author: Vinícius Dantas (viniciusd) * Date: 2017-03-01 16:21
I have been browsing around the unittest standard library, and I realized that TestCase's shortDescription() method at lib/pythonX.X/unittest/case.py returns None when the there is no docstring on the test that is running.
As shortDescription() should obviously return a string, I would recommend returning an empty string instead of None when no docstring is found.
This came to mind when I was using testscenario package, which only displays the scenarioname when shortDescription() returns something but None.
When we are starting from scratch a test suite, docstrings are left for another stage, when we have running (probably failed, if we are TDDing) unittests.
Last yet not least, I am sure it's a good practice to avoid returning None, which forces None-checks, returning empty strings, lists, objects of the return type expected from that function.
msg288764 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-03-01 17:28
This can break a code that checks whether shortDescription() is None.

If you an empty string rather than None, just use the expression `shortDescription() or ''`.
msg288766 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2017-03-01 17:33
It's too late to change this API.  As Serhiy says, it risks breaking code that is currently running and correct.

Note the the __doc__ on functions is set to None when there is no docstring.  For better or worse, returning None is common in the Python world.
msg288768 - (view) Author: Vinícius Dantas (viniciusd) * Date: 2017-03-01 17:43
If it is tagged for future releases, whoever choose to update their Python
version should expect code breaking and API changes, shouldn't them? I
don't see code breaking as an issue against this request.

On 1 March 2017 at 14:33, Raymond Hettinger <report@bugs.python.org> wrote:

>
> Raymond Hettinger added the comment:
>
> It's too late to change this API.  As Serhiy says, it risks breaking code
> that is currently running and correct.
>
> Note the the __doc__ on functions is set to None when there is no
> docstring.  For better or worse, returning None is common in the Python
> world.
>
> ----------
> nosy: +rhettinger
> resolution:  -> rejected
> stage:  -> resolved
> status: open -> closed
>
> _______________________________________
> Python tracker <report@bugs.python.org>
> <http://bugs.python.org/issue29686>
> _______________________________________
>

-- 
Vinícius Dantas de Lima Melo
Graduando em Ciências e Tecnologia
Universidade Federal do Rio Grande do Norte (UFRN)
Escola de Ciências e Tecnologia (ECT)
Natal, Rio Grande do Norte
vinicius.gppcom@gmail.com viniciusdantas@bct.ect.ufrn.br
vinicius.dantasdelimamelo@mail.utoronto.ca | Celular/Mobile Phone: +1 647
447 5737
Skype: viniciusdantas01
msg288770 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2017-03-01 17:55
We don't make breaking changes unless there is strong motivation, which is lacking here.
msg289169 - (view) Author: Vinícius Dantas (viniciusd) * Date: 2017-03-07 15:55
In the point of view of a tester, if it's an error, they will know right
away it is a test case problem, not an assert problem. That makes debugging
easier.
It is also important to note that, if it's an AssertionError, we may add a
message. While, if it is an error, no message would be displayed but the
original Exception's.

As Selenium's example, as I said, was just a use case example.

Finally, having the failure reason explicit is better than keeping it
implicit.
History
Date User Action Args
2022-04-11 14:58:43adminsetgithub: 73872
2017-03-07 15:55:36viniciusdsetmessages: + msg289169
2017-03-01 17:55:14r.david.murraysetnosy: + r.david.murray
messages: + msg288770
2017-03-01 17:43:07viniciusdsetmessages: + msg288768
2017-03-01 17:33:46rhettingersetstatus: open -> closed

nosy: + rhettinger
messages: + msg288766

resolution: rejected
stage: resolved
2017-03-01 17:28:27serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg288764
2017-03-01 16:57:15viniciusdsetpull_requests: + pull_request319
2017-03-01 16:21:40viniciusdcreate