find_package_names test fails inside devcontainer
Closed this issue · 7 comments
It is kind of weird to create an issue about my own contribution, but I am really stuck trying to resolve it 🙁
This is what happens:
______________________________ test_find_package_names _______________________________
def test_find_package_names():
> packages = find_package_names()
/workspaces/repo-pydeps@aleks-ivanov/tests/test_package_names.py:7:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
def find_package_names():
site_packages = sysconfig.get_paths()['purelib']
# initialize with well-known packages that don't seem to have a top_level.txt
res = {
'yaml': 'PyYAML',
'Crypto': 'pycrypto',
}
> for pth in os.listdir(site_packages):
E FileNotFoundError: [Errno 2] No such file or directory: '/usr/lib/python3.9/site-packages'
/workspaces/repo-pydeps@aleks-ivanov/pydeps/package_names.py:14: FileNotFoundError
================================== warnings summary ==================================
pydeps/mf27.py:7
/workspaces/repo-pydeps@aleks-ivanov/pydeps/mf27.py:7: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
import imp
-- Docs: https://docs.pytest.org/en/stable/warnings.html
============================== short test summary info ===============================
FAILED tests/test_package_names.py::test_find_package_names - FileNotFoundError: [E...
====================== 1 failed, 39 passed, 1 warning in 19.13s ======================
Any ideas why this happens ?
Building the docker container I see:
# python3 -V
Python 3.9.2
# python3
Python 3.9.2 (default, Feb 28 2021, 17:03:44)
[GCC 10.2.1 20210110] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sysconfig
>>> sysconfig.get_paths()['purelib']
'/usr/lib/python3.9/site-packages'
>>>
# cd /usr/lib/python3.9
# ls -ld */ | grep package
#
so the directory isn't there.
I would also expect the directory to be named .../dist-packages/
on debian derivatives, so there's that.
pip
gives the real directory:
# pip -V
pip 21.2.4 from /usr/local/lib/python3.9/dist-packages/pip (python 3.9)
which does exist...
That is why this happens. I'm not sure what the fix is yet...
I have asked on SO: https://stackoverflow.com/questions/69303826/finding-python-site-package-directory-in-debian-container
(there is one more way to find the site-packages directory import site;print(site.getsitepackages()
, I'll see how that works..)
The latest checkin should fix the problem.
@thebjorn the same test still fails, but the error has changed to:
_________________________________________________________________________________________________ test_find_package_names _________________________________________________________________________________________________
def test_find_package_names():
packages = find_package_names()
assert 'pip' in packages
> assert 'pytest' in packages
E AssertionError: assert 'pytest' in {'Crypto': 'pycrypto', 'flake8': 'flake8', 'mccabe': 'mccabe', 'pip': 'pip', ...}
/workspaces/pydeps/tests/test_package_names.py:9: AssertionError
==================================================================================================== warnings summary =====================================================================================================
pydeps/mf27.py:7
/workspaces/pydeps/pydeps/mf27.py:7: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
import imp
-- Docs: https://docs.pytest.org/en/stable/warnings.html
================================================================================================= short test summary info =================================================================================================
FAILED tests/test_package_names.py::test_find_package_names - AssertionError: assert 'pytest' in {'Crypto': 'pycrypto', 'flake8': 'flake8', 'mccabe': 'mccabe', 'pip': 'pip', ...}
======================================================================================== 1 failed, 40 passed, 1 warning in 11.86s =========================================================================================
Aside from that we are currently working on a more robust version of the devcontainer and will contribute it soon.
Hmm.. it worked when I created the container and ran it outside vscode. I'm looking into it now.
ok, so pytest has landed in /home/vscode/.local/lib/python3.9/site-packages/
... Fixed in latest checkin.