Import errors on subsystems for ZODB, but only for Py.Test

244 views Asked by At

Running PyTest with files including ZODB gives an odd problem: ZODB can be imported, but its component FileSystem cannot.

import ZODB   # That works fine.
import ZODB.FileStorage
ImportError: No module named FileStorage

On the other hand, running the same code from the Python interpreter runs fine.

This is version PyTest version 3.2.2, Python 2.7.13, and ZODB 5.2.4 There exists ZODB-5.2.4-py2.7.egg/ZODB/FileStorage/init.py, a ZODB.pth pointing to the egg, and no other modules have issues; just any submodule of ZODB. No odd permission errors. After an hour of experiments and exercising Google-Fu, I got nothing.

Any workaround would be appreciated.

Well, I dropped this because it 'went away'. Now its back. This I know so far:

  • This shows up sometimes with PyTest, usually running a profiler. I haven't found a way around it. I don't know what causes it. I have some issues filed but haven't tracked it down.

    File "/Users/cmerriam/p/platform/zzz/data/ZODB.py", line 41, in <module>
    import ZODB.FileStorage                                 # flake8: noqa
    ImportError: No module named FileStorage
    

Things I see:

  * Same issue from PyCharm or command line.
  * No issue running normal code from PyCharm or command line.
  * Once it starts to be an issue, it continues.  Still don't know why.
  * Once it goes away it stays away.
  * My edit configuration has a warning "No Py.Test runner found for current configuration", though 
  /opt/zzz/bin/py.test is in path
  * Seems to have occurred after a reboot.
  * No reason, at all, to suspect FileStorage.
  * This is in my ...../site-packages directory:


        $ ls -l ZODB*
        -rw-rw-r--  1 cmerriam  zzz  23 Oct  6 18:08 ZODB.pth

        ZODB-5.2.4-py2.7.egg:
        total 0
        drwxr-xr-x   9 cmerriam  zzz   306 Oct  6 18:08 EGG-INFO/
        drwxr-xr-x  74 cmerriam  zzz  2516 Oct  9 15:58 ZODB/


        $ cd ZODB-5.2.4-py2.7.egg
        $ tree
           |-EGG-INFO
           |-ZODB
           |---FileStorage
           |---__pycache__
           |---scripts
           |-----manual_tests
           |-----tests
           |---tests

Things that haven't worked:

  • Uninstall and reinstall PyTest
  • Restart pycharm checking environment
  • Right-click in project "clean compiled python files"
  • Running regular python test first.
  • Running pytest from command line in different directories
  • Reboot again
  • Pip Install pytest-runner
  • Install new zzz version
  • Run 'python setup.py install'
  • Moving ZODB-5.2.4-py2.7.egg/EGG-INFO/ to ZODB-5.2.4-py2.7.egg-info

Aha! A CLUE!

There exists in the system a module named zzz.data.zodb.py. And I'm working on OS/X which is case preserving but not case sensitive. And yet I got a point with both "zzz.data.zodb" and "zzz.data.ZODB" in my sys.modules. And can we just make it an error to have two items align but for case yet?

I still would like nail down the edge cases of what happened.

2

There are 2 answers

0
A. Dickey On

Have you tried the following:

from ZODB import FileStorage
0
AudioBubble On

Try Something Like the following as discribed in another answer:

@A. Dickey -

from ZODB import FileStorage

In the comments discribes:

@nes -
Maybe module with same name located in sys.path. Try to see which files module uses import ZODB; print(ZODB.__file__)