AttributeError: 'module' object has no attribute '__path__'

Issue #410 resolved
Ned Batchelder
repo owner created an issue

This seems to happen on py 3.4+ with unusual imports.

Here's a failing Travis build: https://travis-ci.org/mgedmin/irclog2html/jobs/81338508

$ coverage run --source=irclog2html -m zope.testrunner.__init__ --test-path=src
Coverage.py warning: Module irclog2html was never imported.
Coverage.py warning: No data was collected.
Traceback (most recent call last):
  File "/home/travis/virtualenv/python3.4.2/bin/coverage", line 9, in <module>
    load_entry_point('coverage==4.0', 'console_scripts', 'coverage')()
  File "/home/travis/virtualenv/python3.4.2/lib/python3.4/site-packages/coverage/cmdline.py", line 694, in main
    status = CoverageScript().command_line(argv)
  File "/home/travis/virtualenv/python3.4.2/lib/python3.4/site-packages/coverage/cmdline.py", line 435, in command_line
    return self.do_run(options, args)
  File "/home/travis/virtualenv/python3.4.2/lib/python3.4/site-packages/coverage/cmdline.py", line 569, in do_run
    self.run_python_module(args[0], args)
  File "/home/travis/virtualenv/python3.4.2/lib/python3.4/site-packages/coverage/execfile.py", line 107, in run_python_module
    pathname, packagename = find_module(modulename)
  File "/home/travis/virtualenv/python3.4.2/lib/python3.4/site-packages/coverage/execfile.py", line 44, in find_module
    spec = importlib_util_find_spec(mod_main)
  File "/home/travis/virtualenv/python3.4.2/lib/python3.4/importlib/util.py", line 87, in find_spec
    return _find_spec(fullname, parent.__path__)
AttributeError: 'module' object has no attribute '__path__'

It should be reproducible by checking out https://github.com/mgedmin/irclog2html/tree/2154cf870f3073a71471bb2863be64827c3d90c1 and then running "tox -e py34"

Comments (6)

  1. Marius Gedminas
    $ .tox/py34/bin/python -i -m coverage run --source=irclog2html -m zope.testrunner.__init__ --test-path=src 
    Coverage.py warning: Module irclog2html was never imported.
    Coverage.py warning: No data was collected.
    Traceback (most recent call last):
      File "/usr/lib/python3.4/runpy.py", line 170, in _run_module_as_main
        "__main__", mod_spec)
      File "/usr/lib/python3.4/runpy.py", line 85, in _run_code
        exec(code, run_globals)
      File "/home/mg/src/irclog2html/.tox/py34/lib/python3.4/site-packages/coverage/__main__.py", line 8, in <module>
        sys.exit(main())
      File "/home/mg/src/irclog2html/.tox/py34/lib/python3.4/site-packages/coverage/cmdline.py", line 694, in main
        status = CoverageScript().command_line(argv)
      File "/home/mg/src/irclog2html/.tox/py34/lib/python3.4/site-packages/coverage/cmdline.py", line 435, in command_line
        return self.do_run(options, args)
      File "/home/mg/src/irclog2html/.tox/py34/lib/python3.4/site-packages/coverage/cmdline.py", line 569, in do_run
        self.run_python_module(args[0], args)
      File "/home/mg/src/irclog2html/.tox/py34/lib/python3.4/site-packages/coverage/execfile.py", line 107, in run_python_module
        pathname, packagename = find_module(modulename)
      File "/home/mg/src/irclog2html/.tox/py34/lib/python3.4/site-packages/coverage/execfile.py", line 44, in find_module
        spec = importlib_util_find_spec(mod_main)
      File "/home/mg/src/irclog2html/.tox/py34/lib/python3.4/importlib/util.py", line 87, in find_spec
        return _find_spec(fullname, parent.__path__)
    AttributeError: 'module' object has no attribute '__path__'
    >>> import pdb
    >>> pdb.pm()
    > /home/mg/src/irclog2html/.tox/py34/lib/python3.4/importlib/util.py(87)find_spec()
    -> return _find_spec(fullname, parent.__path__)
    (Pdb) p parent
    <module 'zope.testrunner.__init__' from '/home/mg/src/irclog2html/.tox/py34/lib/python3.4/site-packages/zope/testrunner/__init__.py'>
    (Pdb) p fullname
    'zope.testrunner.__init__.__main__'
    (Pdb) parent.__path__
    *** AttributeError: 'module' object has no attribute '__path__'
    
  2. Marius Gedminas

    Some background for the strange -m zope.testrunner.__init__ if anyone's interested:

    • I used to use zc.buildout a lot. The zc.recipe.testrunner would create a bin/test script that worked fine, but didn't work when run with bin/coverage run bin/test. I didn't investigate because life's too short and yaks are hairy.
    • bin/coverage -m zope.testrunner works today, but didn't work back then because zope.testrunner didn't have a __main__.py. Besides, I wanted to support Python 2.6 too, and __main__.py wasn't a thing on 2.6.
    • zope.testrunner had a main() in __init__.py because, IIRC, somebody submitted a patch that made python -m zope.testrunner work back when Python 2.5 was current.
    • Therefore I tried bin/coverage -m zope.testrunner.__init__, found that it works, and kept it. Again, had no time to go deep and shave all the yaks (although I found some time later on to add a zope/testrunner/__main__.py and push out a release).
    • Today there's no reason to use coverage run -m zope.testrunner.__init__, so this bug doesn't hurt me personally.

    Anyway, I'm looking at the source and I think coverage.py is making some unwarranted assumptions.

  3. Log in to comment