test / pkg_resources crashes on native (__init__.py-less) namespace package
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 2.9k
- Forks
- 1.4k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 1
Description
setup.py test fails with a confusing exception if the test suite is a "py3 native" namespace package (no __init__.py).
Reproducer
setup.py:
from setuptools import setup
setup(name='reproducer',
version='0.0',
test_suite='tests',
)
tests is an empty directory (it might have some tests, but no __init__.py)
Run python setup.py test
Result
Traceback (most recent call last):
File ".../setup.py", line 3, in <module>
setup(name='reproducer',
...
File ".../unittest/loader.py", line 220, in loadTestsFromNames
suites = [self.loadTestsFromName(name, module) for name in names]
...
File ".../setuptools/command/test.py", line 47, in loadTestsFromModule
for file in resource_listdir(module.__name__, ''):
File ".../pkg_resources/__init__.py", line 1162, in resource_listdir
return get_provider(package_or_requirement).resource_listdir(
File ".../pkg_resources/__init__.py", line 364, in get_provider
return _find_adapter(_provider_factories, loader)(module)
File ".../site-packages/pkg_resources/__init__.py", line 1392, in __init__
self.module_path = os.path.dirname(getattr(module, '__file__', ''))
File ".../posixpath.py", line 152, in dirname
p = os.fspath(p)
TypeError: expected str, bytes or os.PathLike object, not NoneType
I know pkg_resources is being deprecated in favor of importlib.resources, but ... this is setuptools itself using it.
I'm also aware there are better alternatives to setup.py test (but if the official position is "don't use it", I'd welcome a statement from setuptools maintainers saying that, so I can link people to it).
Filing this mostly to let you know. I don't really mind if this isn't fixed.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the failure with the shown setup.py and empty tests directory using python setup.py test. Read setuptools/command/test.py and pkg_resources/init.py at the traceback locations, then verify that testing a native namespace package no longer crashes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- build-system, testing
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100