Why does mocking 'open' and returning a FileNotFoundError raise AttributeError: __exit__?
问题 Testing by mocking open with a FileNotFoundError raises AttributeError: __exit__ . Why is this happening and what can I do to fix it? The following code opens a simple text file. If the file is missing it generates a default value. It has been checked by regular running and it appears to be working perfectly. so_main.py import os import so_config def load_savelocation(): path = os.path.join(so_config.ROOT, so_config.SAVELOCATION_FN) savelocation_path = os.path.normpath(path) try: with open