carsongee / pytest-pylint

pytest plugin for running pylint against your codebase
MIT License
74 stars 34 forks source link

INTERNALERROR> ValueError '/path/to/test_runfiles/__init__.py' ("{!r} is not in the subpath of {!r}" #190

Open geaden opened 10 months ago

geaden commented 10 months ago

I run pytest-pylint as part of bazel build inspired by this article.

Unfortunately, after updating to latest version of pytest-pylint, I'm getting:

INTERNALERROR>   File "//path/to/tools/tools/tools_test.runfiles/rules_python~0.24.0~pip~py_deps_311_pytest_pylint/site-packages/pytest_pylint/plugin.py", line 257, in <listcomp>
INTERNALERROR>     str((root_path / file_path).relative_to(getcwd()))
INTERNALERROR>         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR>   File "/private/var/tmp/_bazel_geaden/6f98a3a65d0c1b35c4c31e9340fbc46d/execroot/_main/external/rules_python~0.24.0~python~python_3_11_aarch64-apple-darwin/lib/python3.11/pathlib.py", line 730, in relative_to
INTERNALERROR>     raise ValueError("{!r} is not in the subpath of {!r}"
INTERNALERROR> ValueError: '/path/to/tools/tools/tools_test.runfiles/__init__.py' is not in the subpath of '/path/to/tools/tools/tools_test.runfiles/_main' OR one path is relative and the other is absolute.

My pytest_wrapper.py:

if __name__ == "__main__":
  import os
  import pytest
  import sys
  dirs = set(map(os.path.dirname, sys.argv[1:]))
  for d in dirs:
    if not d in sys.path:
      sys.path.append(d)
  result = pytest.main(list(dirs))
  raise SystemExit(result)

pytest-pylint version 0.21.0 pytest version 7.4.3

This started to occurr after this changes https://github.com/carsongee/pytest-pylint/commit/2a75f58eb267f8215a6c171c9e9b11f8f7ac669b#diff-e9aebdea893cd9c55222417aee3fa7c2579438f5b735a3ca7217b7a544f78bf9.

Any clues on how to resolve this?

geaden commented 10 months ago

There are some workarounds made in pytestfakefs https://github.com/pytest-dev/pyfakefs/pull/828. Maybe they are related