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

test / pkg_resources crashes on native (__init__.py-less) namespace package #1827

Open
encukou opened this issue Aug 21, 2019 · 1 comment
Open

Comments

@encukou
Copy link
Contributor

encukou commented Aug 21, 2019

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.

@pganssle
Copy link
Member

pganssle commented Aug 21, 2019

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).

The official position is indeed "don't use it", we just need to implement the "statement" part. For now you can link to #931 and #1684.

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

No branches or pull requests

2 participants