lajarre
lajarre

Reputation: 5162

Python unittest - multiple assertions => don't fail if at least of one them passes

I'm doing that at the moment:

try:
    self.assertIsNotNone(a)
except AssertionError:
    try:
        self.assertIsTrue(b)
    except AssertionError:
        try:
            self.assertIn(c, C)
        except AssertionError:
            self.assertIsInstance(d, D)

(any of these assertions should pass)

How to do that better?

--

UPDATE: use any kind of assertion

Upvotes: 0

Views: 167

Answers (1)

unutbu
unutbu

Reputation: 879083

You could use:

self.assertFalse(any(x is None for x in (a, b, c, d)))

Upvotes: 2

Related Questions