Improve error handling in document import
Update tests.py