Skip to content

pytest fails with implicit namespaces #5590

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

Closed
aatkinson opened this issue Jul 10, 2019 · 2 comments
Closed

pytest fails with implicit namespaces #5590

aatkinson opened this issue Jul 10, 2019 · 2 comments
Labels
status: needs information reporter needs to provide more information; can be closed after 2 or more weeks of inactivity

Comments

@aatkinson
Copy link

Pytest doesn't seem to work with implicit namespaces in your source, as defined by PEP 420. This still occurs as of pytest 5.0.1 installed in a Python 3 environment.

Note this is for the source package being tested, and I've encountered the issue with tests outside of the source package (init.py files are required for tests as noted in the best practices document.

E.g.

mypkg/
    foo/
        baz.py
    bar/
        baz.py
tests/

will yield errors like

./../../.local/lib/python3.6/site-packages/py/_path/local.py:721: in pyimport
    raise self.ImportMismatchError(modname, modfile, self)
E   py._path.local.LocalPath.ImportMismatchError: ('baz', '/home/vsts/work/1/s/mkpkg/foo/baz.py', local('/home/vsts/work/1/s/mkpkg/bar/mkpkg.py'))

This issue has appeared in #774.

@asottile
Copy link
Member

I cannot reproduce, did you cp -r the foo and bar directories?

$ find mypkg/ tests -name '*.py' | xargs tail -n999
==> mypkg/bar/baz.py <==

==> mypkg/foo/baz.py <==

==> tests/test_foo.py <==
import mypkg.foo.baz
import mypkg.bar.baz


def test(): pass

$ python -m pytest tests
============================= test session starts ==============================
platform linux -- Python 3.6.8, pytest-5.0.1, py-1.8.0, pluggy-0.12.0
rootdir: /tmp/x
collected 1 item                                                               

tests/test_foo.py .                                                      [100%]

=========================== 1 passed in 0.01 seconds ===========================

@asottile asottile added the status: needs information reporter needs to provide more information; can be closed after 2 or more weeks of inactivity label Jul 10, 2019
@Zac-HD
Copy link
Member

Zac-HD commented Nov 26, 2019

Closing as stale; I can't reproduce it either (and #774 was test files, not code files).

@Zac-HD Zac-HD closed this as completed Nov 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: needs information reporter needs to provide more information; can be closed after 2 or more weeks of inactivity
Projects
None yet
Development

No branches or pull requests

3 participants