For testing and re-usage purposes I pickled some data-structures created during user-interaction within my views.py
.
Now, as I'm writing the tests for these objects I'm constantly encountering ModuleNotFoundError
s (No module named 'Network'
) and did a little research. According to Python pickling after changing a module's directory I'm pretty sure I've been theviolating any of the constraints:
pickle can save and restore class instances transparently, however the class definition must be importable and live in the same module as when the object was stored
I'm unable to figure out if my tests.py and the views.py are actually executed in the same module. I assume they are. Folder Structure:
├── PickleDjango
│ ├── admin.py
│ ├── apps.py
│ ├── forms.py
│ ├── functions.py
│ ├── __init__.py
│ ├── models.py
│ ├── tests.py
│ ├── urls.py
│ └── views.py
├── unittests.py
unittests.py
from the root directory executes the tests.py by simply loading it with:
suite.addTest(loader.loadTestsFromModule(PickleDjango.tests))
inside tests.py
the error occurs in the following line:
orig_obj = pickle.load(infile)
I assume here might be the critical point as the tests.py
is in a sub-module. But it should work when the tests are started from the same module as views.py
. Just from where is the views.py
executed? The root-folder (like unittests.py
) or somewhere else?
Aucun commentaire:
Enregistrer un commentaire