prospector icon indicating copy to clipboard operation
prospector copied to clipboard

[BUG] Relative import false negatives

Open rpatterson opened this issue 2 years ago • 1 comments

Describe the bug

If ./src/foo/tests/__init__.py defines a project-specific base test case class:

class FooTestCase(unittest.TestCase):

And then an actual test module uses a relative import to use that base class:

from .. import tests

class BarTests(tests.FooTestCase):

Running $ pylint ./src/foo directly doesn't report any error but running $ prospector ./src/foo reports pylint: relative-beyond-top-level / Attempted relative import beyond top-level package.

To Reproduce Steps to reproduce the behavior:

  1. $ prospector ./src/foo

Expected behavior

Prospector should report no errors the same as running PyLint directly does.

Environment:

  • OS: Docker python:3.11 image
  • Tool: pylint
  • Prospector version: v1.9.0
  • Python version: v3.11.2

Additional context

I've also observed this with from . import bar relative imports so I think the issue is a general issue with relative imports and not specific to just the given example case.

rpatterson avatar Feb 20 '23 22:02 rpatterson

May be related to my other Prospector issue. It seems like Prospector may be stripping some context or not providing some context that PyLint uses to identify package hierarchy, class hierarchy, etc..

rpatterson avatar Feb 20 '23 22:02 rpatterson