Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
nedbat opened this issue Sep 24, 2015 · 8 comments
Closed

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

nedbat opened this issue Sep 24, 2015 · 8 comments
Labels
bug Something isn't working question Further information is requested run

Comments

@nedbat
Copy link
Owner

nedbat commented Sep 24, 2015

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

#!python
$ 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"


@nedbat
Copy link
Owner Author

nedbat commented Oct 1, 2015

Original comment by Frank Wiles (Bitbucket: frankwiles, GitHub: frankwiles)


FYI I actually got this to happen on Python 2.7.6 also so don't think it's Python 3 related at all. coverage==3.7.1

@nedbat
Copy link
Owner Author

nedbat commented Oct 13, 2015

Original comment by Marius Gedminas (Bitbucket: mgedmin, GitHub: mgedmin)


$ .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__'

@nedbat
Copy link
Owner Author

nedbat commented Oct 13, 2015

Original comment by Marius Gedminas (Bitbucket: mgedmin, GitHub: mgedmin)


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.

@nedbat
Copy link
Owner Author

nedbat commented Oct 13, 2015

Fixed in 8dd7304852a0 (bb)

@nedbat nedbat closed this as completed Oct 13, 2015
@nedbat nedbat added major bug Something isn't working run labels Jun 23, 2018
@Habush
Copy link

Habush commented Nov 19, 2018

Still getting this error on python version 3.6.5 and coverage version 4.5.2

@nedbat
Copy link
Owner Author

nedbat commented Nov 19, 2018

@Habush Can you provide me with instructions to reproduce the problem?

@Habush
Copy link

Habush commented Nov 19, 2018

I just ran coverage run -m tests.<test_file>. I think the issue is occurring because I am improting variables in init.py file. If I move those variables to other file then it works without an issue

@nedbat
Copy link
Owner Author

nedbat commented Nov 19, 2018

@Habush I would love to fix the problem, but I can't unless I can reproduce it. Can you link me to your code, and instructions for how to configure the environment and run the tests?

@nedbat nedbat added the question Further information is requested label Nov 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working question Further information is requested run
Projects
None yet
Development

No branches or pull requests

2 participants