vendredi 1 avril 2016

Test if Warning was issued

I am creating a class and assigning one of it's attributes to a variable

val = ClassName(*args).val

While creating this class a function is called which issues a Warning. I have verified this by using print statements before and after. How do I check for the warning using py.test? I have tried the following after looking at the documentation:

def test_warning(self, recwarn):
     val = ClassName(*args).val
    `assert recwarn.pop(RuntimeWarning)`

This tells me that RuntimeWarning was never issued.

AssertionError: <type 'exceptions.RuntimeWarning'> not found in warning list

What am I missing?

Aucun commentaire:

Enregistrer un commentaire