Open
Description
Bug description
Hi everyone,
First, I'm not entirely sure if this is a bug in pylint.
When working with unittests in a separate folder (the sources root is of course appended to pythonpath), it happens that while pylint is able to resolve all imports from my project as intended, it is only unable to find the __main__.py
in the foo
namespace.
Project structure:
MyProject
├── src
│ └── foo
│ ├── __init__.py
│ ├── __main__.py
│ └── bar.py
└── unittests
└── test_foo.py
With the files contents:
__main__.py
"""
This module is the main entry point for the package.
"""
def cli():
"""Some entry point function"""
bar.py
"""
Some module-level documentation
"""
def bar_func():
"""Some function-level documentation"""
test_foo.py
"""
Test import behaviour of pylint
"""
# pylint: disable=unused-import
from foo.bar import bar_func
from foo.__main__ import cli
Two things to note here:
- The import from
foo.bar
works without problems. Only the import fromfoo.__main__
doesn't resolve. - When I add an import into
__init__.py
likefrom .__main__ import cli
and usefrom foo import cli
in the test, it works. No linter errors in the__init__.py
.
So question is: Why is from foo.__main__ import cli
bad? Is this a bug in pylint?
Configuration
No response
Command used
pylint .\unittests\test_foo.py
Pylint output
************* Module test_foo
unittests\test_foo.py:6:0: E0401: Unable to import 'foo.bar' (import-error)
unittests\test_foo.py:7:0: E0401: Unable to import 'foo.__main__' (import-error)
Expected behavior
Expect to not throw an error in the test-file. It executes without problems.
Pylint version
Tested on two environments with same result:
pylint 3.2.7
astroid 3.2.4
Python 3.12.4 (tags/v3.12.4:8e8a4ba, Jun 6 2024, 19:30:16) [MSC v.1940 64 bit (AMD64)]
and
pylint 3.3.1
astroid 3.3.4
Python 3.12.4 (tags/v3.12.4:8e8a4ba, Jun 6 2024, 19:30:16) [MSC v.1940 64 bit (AMD64)]
OS / Environment
Windows 11
Additional dependencies
No response