Remove unused import
Use pytest to capture exception