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

pathlib: Fix module path used when using importlib with namespaces #12313

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

isra17
Copy link

@isra17 isra17 commented May 12, 2024

Closes #12044

Will do other steps from the template, but before I would like a confirmation that this fix make sense.

It does fix the issue of assertion rewriting mixed with namespace package on in my environment.

If fixes both the cases where the tests lives in a package with __init__.py and with the config consider_namespace_packages = true. I am not familiar at all with this part of the code (or any to be honest), so I'm unsure what are the consequence, but from my understanding the from_spec(module, path) path parameter should take the module parent path, not the source root.

From the doc:

path will be the value of path from the parent package.

@nicoddemus since you seem the main maintainer of this part.

Thanks!

@isra17
Copy link
Author

isra17 commented May 12, 2024

On a local test:

src/
  p1/foo/p1/
    tests/
      test_p1.py
    __init__.py
    test_p1.py
  p2/foo/p2/
    __init__.py
    test_p2.py

Without the fix:

FAILED src/p1/foo/p1/test_p1.py::test_p1 - AssertionError
FAILED src/p1/foo/p1/tests/test_p1.py::test_p1 - AssertionError
FAILED src/p2/foo/p2/test_p2.py::test_p2 - AssertionError

With the fix:

FAILED src/p1/foo/p1/test_p1.py::test_p1 - assert False is True
 +  where False = p1()
FAILED src/p1/foo/p1/tests/test_p1.py::test_p1 - assert False is True
 +  where False = p1()
FAILED src/p2/foo/p2/test_p2.py::test_p2 - assert False is True
 +  where False = p2()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

--import-mode=importlib breaks assertion rewriting
1 participant