Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.Sign up
ensure we follow PEP-235 on case-insensitive filesystems #2761
Running PyTest with files including ZODB gives an odd problem: ZODB can be imported, but its component FileSystem cannot.
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
Any workaround would be appreciated.
Hi. Sorry, I got slammed and didn't make a trimmed down example. This might help:
Well, I dropped this because it 'went away'. Now its back. This I know so far:
As an FYI, there exists PEP 235 to address case sensitivity, sort of.
Would you still think of this as a problem in that Python and Py.Test created different behaviors? The offending lines were, inside of my data/zodb.py:
and in another file in the same data/ directory:
import ZODB # wanting the package ZODB in site-packages.
To be more clear, when doing an
These assertions pass under pytest, but not under python:
mods to site-packages/cbmx/data/zodb.py
We made one or two 'toy' file structures but cannot make pytest fail on the toys, yet.
As a bit more information on this bug, I'm looking at the offending 'import ZODB'.
First, we call
The execution continues through AssertionRewrite's
The TL;DR, some import hook is getting the wrong name, like a resolver function, and deciding to tack the 'cbmx.data' on the front of a non-relative import.
OK. To reframe this:
This only happens with case-insensitive volumes, such as the default OS/X file systems and default Windows filesystem. It only happens with PyTest, not Python. It appears to only happen after a relative import.
@merriam thanks for diving into this; those kind of bugs are the worst to track down.
Continuing the execution, I hit that same breakpoint again but now name is
I can see that in that case,
Here it makes sense to return
But then, continuing the debugging session (I was typing this while debugging), I noticed that actually everything works for me and my test passes.
I decided to leave my notes here anyway because I think it could shine an understanding on how things work with the rewrite hook.
@merriam I created my project like this:
# file: zodb.py import ZODB.FileStorage stuff = 1 # file: test_foo.py from .zodb import stuff def test(): pass # file: __init__.py is empty
I'm using Python 2.7, and tried this experiment on
Thanks again for your efforts on this, we appreciate it.
I'm a bit confused by the layout, and I'll take a crack this week at the consistency failing minimal ayout. My walkthough (OS/X, Python 2.7) did have a line in zodb.py of 'import ZODB' call find_module('thing.ZODB') instead find_module('ZODB'). The FileStorage error was simply that on the recursive find_module call (thing.zodb calling for thing.ZODB), it ran across trying to find the FileStorage feature.
In other words, it fails at the arguments to find_module(), and the rest is just the particular trainwreck that follows.
Could you do a quick recheck, changing
Thank you for looking into this.
Here's a minimal reproduction:
$ touch x/Y.py $ touch y.py $ PYTHONPATH=.:x python3 Python 3.7.3 (default, Mar 27 2019, 09:23:15) [Clang 10.0.1 (clang-1001.0.46.3)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import imp __main__:1: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses >>> imp.find_module('Y') (<_io.TextIOWrapper name='Y.py' mode='r' encoding='utf-8'>, 'Y.py', ('.py', 'r', 1)) >>> import importlib.machinery >>> importlib.machinery.PathFinder.find_spec('y') ModuleSpec(name='y', loader=<_frozen_importlib_external.SourceFileLoader object at 0x101e42860>, origin='/private/tmp/y.py') >>> importlib.machinery.PathFinder.find_spec('Y') ModuleSpec(name='Y', loader=<_frozen_importlib_external.SourceFileLoader object at 0x101e13748>, origin='/private/tmp/x/Y.py')
This'll be solved by #5468