This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author danielnoord
Recipients brett.cannon, danielnoord
Date 2022-01-03.12:21:51
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1641212511.26.0.576933804919.issue46241@roundup.psfhosted.org>
In-reply-to
Content
Affected folder structure:
── module_loader
│   ├── __init__.py
├── pyproject.toml
├── setup.cfg
└── tests
    └── test_module_loader.py

```console
❯ cat '/Users/daniel/DocumentenLaptop/Programming/Test/module_loader/module_loader/__init__.py'
from importlib import util


def load_a_spec(modname):
    return util.find_spec(modname)
```

```console
❯ cat '/Users/daniel/DocumentenLaptop/Programming/Test/module_loader/tests/test_module_loader.py'
from module_loader import load_a_spec


def test_me():
    load_a_spec("tests")
```

When I run `pytest` from within the `module_loader` directory and inspect what `load_a_spec` returns I find that it returns:

ModuleSpec(name='tests', loader=<_frozen_importlib_external.SourceFileLoader object at 0x10a4b4820>, origin='/Users/daniel/DocumentenLaptop/Programming/Github/astroid/tests/__init__.py', submodule_search_locations=['/Users/daniel/DocumentenLaptop/Programming/Github/astroid/tests'])

It seems to take the `tests` folder from another project, in this case astroid, and returns its spec. 
This is my `sys.path`, which might be relevant:

```console
for i in sys.path:print(i)
/Users/daniel/DocumentenLaptop/Programming/Test/module_loader/tests
/usr/local/bin
/usr/local/Cellar/python@3.9/3.9.9/Frameworks/Python.framework/Versions/3.9/lib/python39.zip
/usr/local/Cellar/python@3.9/3.9.9/Frameworks/Python.framework/Versions/3.9/lib/python3.9
/usr/local/Cellar/python@3.9/3.9.9/Frameworks/Python.framework/Versions/3.9/lib/python3.9/lib-dynload
/Users/daniel/Library/Python/3.9/lib/python/site-packages
/usr/local/lib/python3.9/site-packages
/Users/daniel/DocumentenLaptop/Programming/Github/astroid
/Users/daniel/DocumentenLaptop/Programming/Github/DanielNoord/docstringformatter
/Users/daniel/DocumentenLaptop/Programming/Test/module_loader
/usr/local/Cellar/pybind11/2.8.1/libexec/lib/python3.9/site-packages
```

Let me know if I'm doing anything wrong, but I would expect the returned spec to be from `module_loader` instead of another project.
History
Date User Action Args
2022-01-03 12:21:51danielnoordsetrecipients: + danielnoord, brett.cannon
2022-01-03 12:21:51danielnoordsetmessageid: <1641212511.26.0.576933804919.issue46241@roundup.psfhosted.org>
2022-01-03 12:21:51danielnoordlinkissue46241 messages
2022-01-03 12:21:51danielnoordcreate