python / importlib_metadata

Library to access metadata for Python packages
https://importlib-metadata.readthedocs.io
Apache License 2.0
122 stars 79 forks source link

6.8.0: pytest is failing in tests/test_api.py::APITests::test_prefix_not_matched` unit #474

Closed kloczek closed 4 months ago

kloczek commented 9 months ago

I'm packaging your module as an rpm package so I'm using the typical PEP517 based build, install and test cycle used on building packages from non-root account.

Here is pytest output:

```console + PYTHONPATH=/home/tkloczko/rpmbuild/BUILDROOT/python-importlib-metadata-6.8.0-2.fc35.x86_64/usr/lib64/python3.8/site-packages:/home/tkloczko/rpmbuild/BUILDROOT/python-importlib-metadata-6.8.0-2.fc35.x86_64/usr/lib/python3.8/site-packages + /usr/bin/pytest -ra -m 'not network' --ignore exercises.py ============================= test session starts ============================== platform linux -- Python 3.8.18, pytest-7.4.2, pluggy-1.3.0 rootdir: /home/tkloczko/rpmbuild/BUILD/importlib_metadata-6.8.0 configfile: pytest.ini plugins: perf-0.13.1, pyfakefs-5.2.3 collected 106 items importlib_metadata/__init__.py ........ [ 7%] importlib_metadata/_collections.py . [ 8%] importlib_metadata/_functools.py .. [ 10%] importlib_metadata/_itertools.py . [ 11%] importlib_metadata/_text.py . [ 12%] tests/_context.py . [ 13%] tests/_path.py .. [ 15%] tests/test_api.py .....................F.............. [ 49%] tests/test_integration.py .. [ 50%] tests/test_main.py .................................... [ 84%] tests/test_py39compat.py . [ 85%] tests/test_zip.py ............... [100%] =================================== FAILURES =================================== _______________________ APITests.test_prefix_not_matched _______________________ self = def test_prefix_not_matched(self): prefixes = 'p', 'pkg', 'pkg.' for prefix in prefixes: with self.subTest(prefix): with self.assertRaises(PackageNotFoundError): > distribution(prefix) E AssertionError: PackageNotFoundError not raised tests/test_api.py:65: AssertionError =========================== short test summary info ============================ FAILED tests/test_api.py::APITests::test_prefix_not_matched - AssertionError:... ======================== 1 failed, 105 passed in 1.10s ========================= ```

Here is list of installed modules in build env

```console Package Version ----------------------------- ------- alabaster 0.7.13 annotated-types 0.6.0 autocommand 2.2.1 Babel 2.13.0 build 1.0.0 cffi 1.16.0 charset-normalizer 3.3.0 cppclean 0.13 cryptography 41.0.3 distro 1.8.0 docutils 0.20.1 domdf-python-tools 3.7.0 exceptiongroup 1.1.3 gpg 1.21.0 idna 3.4 imagesize 1.4.1 importlib-metadata 6.8.0 importlib-resources 6.1.0 inflect 7.1.0 iniconfig 2.0.0 installer 0.7.0 jaraco.classes 3.3.0 jaraco.context 4.3.0 jaraco.env 1.0.0 jaraco.functools 3.9.0 jaraco.packaging 9.4.0 jaraco.text 3.11.1 jaraco.tidelift 1.5.1 jeepney 0.8.0 Jinja2 3.1.2 keyring 24.2.0 MarkupSafe 2.1.3 more-itertools 10.1.0 natsort 8.3.1 packaging 23.2 path 16.7.1 pkg 0.0.0 platformdirs 3.11.0 pluggy 1.3.0 ply 3.11 pycparser 2.21 pydantic 2.4.2 pydantic_core 2.11.0 pyfakefs 5.2.3 Pygments 2.16.1 pyproject_hooks 1.0.0 pytest 7.4.2 pytest-perf 0.13.1 python-dateutil 2.8.2 pytz 2023.3 requests 2.31.0 requests-toolbelt 1.0.0 rst 0.1 rst.linker 2.4.0 SecretStorage 3.3.3 setuptools 68.2.2 setuptools-scm 8.0.4 six 1.16.0 snowballstemmer 2.2.0 Sphinx 7.1.2 sphinxcontrib-applehelp 1.0.4 sphinxcontrib-devhelp 1.0.2 sphinxcontrib-htmlhelp 2.0.3 sphinxcontrib-jsmath 1.0.1 sphinxcontrib-qthelp 1.0.3 sphinxcontrib-serializinghtml 1.1.9 tempora 5.5.0 tomli 2.0.1 typing_extensions 4.8.0 urllib3 1.26.18 wheel 0.41.2 zipp 3.17.0 ```
mtelka commented 7 months ago

The test failed because you have the pkg package installed:

pkg                           0.0.0

Where this package comes from?

jaraco commented 4 months ago

I'm closing this as the issue appears to be an unexpected pkg package in the environment. I quickly scanned through the test fixtures and I don't think they're responsible for creating the pkg package. Next step is to investigate why that's happening and possibly prevent it from happening. Feel free to comment if there's something this project could potentially do differently.

kloczek commented 4 months ago

Trying to retest that found that in case of create some directory in project tree (in this case created by rpm) before start build it fails because because some bits are missing in pyproject.toml

+ /usr/bin/python3 -sBm build -w --no-isolation
* Getting build dependencies for wheel...
error: Multiple top-level packages discovered in a flat-layout: ['SPECPARTS', 'importlib_metadata'].

To avoid accidental inclusion of unwanted files or directories,
setuptools will not proceed with this build.

If you are trying to create a single distribution with multiple packages
on purpose, you should not rely on automatic discovery.
Instead, consider the following options:

1. set up custom discovery (`find` directive with `include` or `exclude`)
2. use a `src-layout`
3. explicitly set `py_modules` or `packages` with a list of names

To find more information, look for "package discovery" on setuptools docs.

ERROR Backend subprocess exited when trying to invoke get_requires_for_build_wheel