vendredi 22 mai 2015

Trying to print an exception error on the pytest screen

        def different_type():
            if types == 'int64':
                pass
            else:
                raise KeyError('field type not recognized')


        def test_TypeErrorHandling():
            with pytest.raises(KeyError) as excinfo:
            different_type()
       assert excinfo.value.message == 'field type not recognized'
       print excinfo.value.message

Currently I have two paragraphs of code and doing a raise exception to try and print out the error message ('field type not recognized') as defined in test_TypeErrorHandling() on the command prompt screen when i do a pytest run. But it won't print out.

Any advise out there? Thanks

Aucun commentaire:

Enregistrer un commentaire