[issue11468] Improve unittest basic example in the doc
New submission from Ezio Melotti
Éric Araujo
Florian Preinstorfer
Senthil Kumaran
Éric Araujo
Changes by Berker Peksag
Raymond Hettinger
Ezio Melotti
Raymond Hettinger
Changes by Berker Peksag
Serhiy Storchaka added the comment:
I think `self.assertRaises(TypeError, s.split, 2)` looks simpler. In any case two examples for assertRaises needed, simple inlined and more complicated use as context manager.
----------
nosy: +serhiy.storchaka
_______________________________________
Python tracker
Ezio Melotti added the comment:
Given that this is a basic example, it's not necessary to introduce both the forms of assertRaises.
I personally find the context manager form more readable, and I prefer it to the regular one even if it takes two lines instead of one.
----------
_______________________________________
Python tracker
Changes by Serhiy Storchaka
Changes by Berker Peksag
Changes by Zachary Ware
Raymond Hettinger added the comment:
FWIW, I'm going to test some other module (math or somesuch) rather than the built-in string methods. The normal use of unittest is to import both the unittest module and the module under test. I want to show that pattern (which is somewhat different from doctests where the tests are typically in the same file as the code being tested).
----------
_______________________________________
Python tracker
Ezio Melotti added the comment:
Raymond, in the meanwhile can the proposed patch be applied?
I don't think it's necessary to show that you need to import a module in order to test its functions. Using modules also has the disadvantage that people might not know what result to expect if they are not familiar with the functions of that module (e.g. the only functions that return True/False in the math module seem to be isfinite/isnan/isinf), whereas everyone should know basic string methods.
----------
_______________________________________
Python tracker
Raymond Hettinger added the comment:
Yes, go ahead an apply this patch.
----------
assignee: rhettinger -> ezio.melotti
_______________________________________
Python tracker
Roundup Robot added the comment:
New changeset 4a2a5fddbab3 by Ezio Melotti in branch '2.7':
#11468: improve unittest basic example. Initial patch by Florian Preinstorfer.
https://hg.python.org/cpython/rev/4a2a5fddbab3
New changeset 010e33b37feb by Ezio Melotti in branch '3.4':
#11468: improve unittest basic example. Initial patch by Florian Preinstorfer.
https://hg.python.org/cpython/rev/010e33b37feb
New changeset d6791e4026f1 by Ezio Melotti in branch 'default':
#11468: merge with 3.4.
https://hg.python.org/cpython/rev/d6791e4026f1
----------
nosy: +python-dev
_______________________________________
Python tracker
Ezio Melotti added the comment:
I tweaked the wording a bit, added a link to the section about setUp/tearDown, and applied it on all the 3 branches.
Thanks for the patch Florian!
----------
resolution: -> fixed
stage: patch review -> resolved
status: open -> closed
_______________________________________
Python tracker
participants (9)
-
Berker Peksag
-
Ezio Melotti
-
Florian Preinstorfer
-
Raymond Hettinger
-
Roundup Robot
-
Senthil Kumaran
-
Serhiy Storchaka
-
Zachary Ware
-
Éric Araujo