If using unittest:
import unittest
with self.assertRaises( Exception ) as error:
...
If using pytest:
import pytest
with pytest.raises( Exception ) as error:
...
A blog about coding
If using unittest:
import unittest
with self.assertRaises( Exception ) as error:
...
If using pytest:
import pytest
with pytest.raises( Exception ) as error:
...