unittest unable to import class from pickle (AttributeError: Can't get attribute…)
问题 I need a unittest to load a previously saved class in a pickle. However, when I load the pickle in the unittest (out of unittest works), it raises the error: AttributeError: Can't get attribute 'Foo' on <module 'unittest. main ' from '...\unittest\ main .py'> Code example to save the class (I save this code in run_and_save_class.py ): from pickle import dump from pickle import load from pickle import HIGHEST_PROTOCOL class Foo(object): def __init__(self): self.bar = None self.file_out = ".