Bug 2138663 - poetry does not run tests in %check
Summary: poetry does not run tests in %check
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Fedora
Classification: Fedora
Component: poetry
Version: rawhide
Hardware: Unspecified
OS: Unspecified
unspecified
medium
Target Milestone: ---
Assignee: Tomáš Hrnčiar
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2022-10-30 21:05 UTC by Miro Hrončok
Modified: 2022-11-10 14:35 UTC (History)
4 users (show)

Fixed In Version: poetry-1.2.1-4.fc38
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2022-11-10 14:35:46 UTC
Type: Bug
Embargoed:


Attachments (Terms of Use)

Description Miro Hrončok 2022-10-30 21:05:13 UTC
poetry-1.2.1-3.fc38 has several problems in %check that were introduced in the latest update

 1. there is a typo "bootstap" (missing r), causing the condition to always evaluate to 0, hence the tests never run
 2. when the typo is fixed, the condition is reversed, should be %if %{without bootstrap}
 3. when the tests run, there are import errors (missing modules flatdict and deepdiff, packages not yet packaged in Fedora)
 4. when the affected files are --ignore'd, there are 14 tests failures, many of them with permission errors writing to /usr/src/demo

A work in progress diff:

-%if %{with bootstap}
+%if %{without bootstrap}
 %check
 # don't use %%tox here because tox.ini runs "poetry install"
 # test_lock_no_update: attempts a network connection to pypi
@@ -79,10 +79,16 @@ done
 #    virtualenv: error: argument dest: the destination . is not write-able at /
 # test_executor and test_editable_builder doesn't work with pytest7
 #    upstream report: https://github.com/python-poetry/poetry/issues/4901
+# the --ignore'd files need not yet packaged flatdict and deepdiff
 %pytest -k "not lock_no_update and \
 not export_exports_requirements_txt_file_locks_if_no_lock_file and \
 not executor and \
-not editable_builder"
+not editable_builder" \
+--ignore tests/config/test_config.py \
+--ignore tests/console/commands/test_config.py \
+--ignore tests/masonry/builders/test_editable_builder.py \
+--ignore tests/test_factory.py \
+--ignore tests/utils/test_dependency_specification.py
 %endif

Comment 1 Miro Hrončok 2022-10-31 16:43:12 UTC
We've talked about this with Tomáš now. Some raw notes before we forget:



5 of the tests fail with:

tests/helpers.py:122: in mock_clone
    dest.parent.mkdir(parents=True, exist_ok=True)

This is here https://github.com/python-poetry/poetry/blob/1.2.1/tests/helpers.py#L124 -- for some reason, source_dir is /usr, which is weird, but the problem seems to be a problem in tests only.

The next step is to determine whether /usr is set from https://github.com/python-poetry/poetry/blob/1.2.1/tests/helpers.py#L121 or from the way the function is called and continue with more detective work from there.


------------


9 tests fail with:

    def get_embedded_wheel(self, distribution: str) -> Path:
        wheel: Wheel = get_embed_wheel(
            distribution, f"{self.version_info[0]}.{self.version_info[1]}"
        )
>       path: Path = wheel.path
E       AttributeError: 'NoneType' object has no attribute 'path'

This is here https://github.com/python-poetry/poetry/blob/1.2.1/src/poetry/utils/env.py#L1270 -- because we patch virtualenv to remove bundled wheels, the get_embed_wheel() function always returns None.
I've proposed hotpatching the function more or less to:

    def get_embedded_wheel(self, distribution: str) -> Path:
        from virtualenv.util.path._system_wheels import get_system_wheels_paths

        wheel_paths = get_system_wheels_paths(self._executable)
        for wheel_dir in wheel_paths:
            pip_wheels = sorted(wheel_dir.glob('pip-*.whl'))
            if not pip_wheels:
                break
            return pip_wheels[0]

        raise RuntimeError(...)

We might talk to Lumír about exposing get_system_wheel("pip") from virtualenv, so we don't need to reimplement that here.
Later, we need to talk to poetry upstream and ask them why they want the embed wheel explicitly rather than "a wheel" and if they just use the embed one because it is easy for them, we might change that as well.

This problem is ubiquitous in the tests because the tested virtualenvs don't have pip in them. That is the default for tests but not for users. However, users can configure their virtualenvs to be pip-less. See https://python-poetry.org/docs/configuration/#virtualenvsoptionsno-pip


tl;dr this has uncovered a problem that can most probably surface to some of our users, hence setting severity to medium (it's rawhide only and requires a specific config option that has not existed in older poetry versions)

Comment 2 Miro Hrončok 2022-11-01 10:30:11 UTC
'pip-*.whl' should have been f'{distribution}-*.whl'

Comment 3 Tomáš Hrnčiar 2022-11-08 15:02:17 UTC
PR: https://src.fedoraproject.org/rpms/poetry/pull-request/32

Comment 4 Fedora Update System 2022-11-10 14:33:14 UTC
FEDORA-2022-b3ab90e661 has been submitted as an update to Fedora 38. https://bodhi.fedoraproject.org/updates/FEDORA-2022-b3ab90e661

Comment 5 Fedora Update System 2022-11-10 14:35:46 UTC
FEDORA-2022-b3ab90e661 has been pushed to the Fedora 38 stable repository.
If problem still persists, please make note of it in this bug report.


Note You need to log in before you can comment on or make changes to this bug.