How to cache Poetry virtual environments?

I want to cache Poetry virtual environments between builds of my Python application. I have configured the pipeline so that the virtual environment is recreated every time pyproject.toml changes (poetry.lock is not comitted):

    - key:
        - lego/pyproject.toml
        - lego/.venv
        - artifacts/build/layer/build/.venv
    - paths:
        - artifacts/pypoetry

The virtual environment is created as follows:

poetry config true
poetry install

This works locally, but it fails in GitLab CI/CD on the second pipeline run:

$ LOG_LEVEL=ERROR poetry run pytest tests -n auto -v --cov=./src --junitxml=lego-report.xml

ImportError while loading conftest '/builds/5565557/lddpro-bff/lego/tests/'.
tests/ in <module>
   from import S3, EventBridge, SSM, Secrets
E ModuleNotFoundError: No module named 'lego'

The reason is that pytest cannot locate the root package (lego). However, I have verified that the root package is located in the virtual environment (.venv):

$ cat .venv/lib/python*/site-packages/lego.pth

Here lego.pth includes the current job ID in the path.

How can I properly cache Poetry virtual environments between CI/CD pipeline runs?