[Python] Python unittest - opposite of assertRaises?

Discussão em 'Python' iniciado por Stack, Julho 14, 2025.

  1. Stack

    Stack Membro Participativo

    I want to write a test to establish that an Exception is not raised in a given circumstance.

    It's straightforward to test if an Exception is raised ...

    sInvalidPath=AlwaysSuppliesAnInvalidPath()
    self.assertRaises(PathIsNotAValidOne, MyObject, sInvalidPath)


    ... but how can you do the opposite.

    Something like this i what I'm after ...

    sValidPath=AlwaysSuppliesAValidPath()
    self.assertNotRaises(PathIsNotAValidOne, MyObject, sValidPath)

    Continue reading...

Compartilhe esta Página