lundi 8 avril 2019

How to use unittest to assert an assert?

Let's say I have this function:

def to_upper(var):
    assert type(var) is str, 'The input for to_upper should be a string'
    return var.upper()

And a file for unit testing using unittest:

class Test(unittest.TestCase):

    def test_1(self):
        -- Code here --


if __name__ == '__main__':
    unittest.main()

How do I test that if I call to_upper(9) it throws an assertion error?

Aucun commentaire:

Enregistrer un commentaire