Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #77005 > unrolled thread
| Started by | Terry Reedy <tjreedy@udel.edu> |
|---|---|
| First post | 2014-08-25 17:47 -0400 |
| Last post | 2014-08-25 17:47 -0400 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: Switching from nose to unittest2 - how to continue after an error? Terry Reedy <tjreedy@udel.edu> - 2014-08-25 17:47 -0400
| From | Terry Reedy <tjreedy@udel.edu> |
|---|---|
| Date | 2014-08-25 17:47 -0400 |
| Subject | Re: Switching from nose to unittest2 - how to continue after an error? |
| Message-ID | <mailman.13433.1409003278.18130.python-list@python.org> |
On 8/25/2014 2:13 PM, Skip Montanaro wrote:
> It appears that unittest in Python 2.7 should be capable enough that I
> can abandon nose in favor of python -m unittest. How do I get it to
> continue past the first failure?
Unittest normally stops with the first failure in a test_function. If
the asserts within a function are dependent (or normally passing), that
may be what you want.
I know of two ways to collect multiple failures within a test function:
1. Do it yourself. For instance, let iopairs be an iterable of input,
expected-output pairs for a function f.
def test_f(self):
failures = []
for inp, expect in iopairs:
actual = f(inp)
if actual != expect:
failures.append((inp, expect, actual))
assertFalse(failures, 'inp, expect, actual triples'
2. Use subtests, new in 3.4, and I suspect backported in unittest2 on
PyPI. This can be combined with the 1. above. Suppose two functions
should both pass the test above.
def test_g_h(self):
for f in (g, h):
with self.subTest(f=f):
<body of test_f>
As for asserts (from next message): self.assertTrue is equivalent to
assert, except it does not disappear with a compile flag. The other
assertX methods resolve to assertTrue, but for some, such as assert
raises, the equivalent in non-trivial. Even when the equivalent is
trivial, the specific methods usually gives better diagnostic messages.
This is especially true when comparing two non-empty collection for
equality. Knowing what is a one but the the other is very helpful.
--
Terry Jan Reedy
Back to top | Article view | comp.lang.python
csiph-web