I have the following Github action, in which I'm specifying Python 3.10:
name: Unit Tests
runs-on: ubuntu-latest
defaults:
  run:
    shell: bash
    working-directory: app
steps:
  - uses: actions/checkout@v3
  - name: Install poetry
    run: pipx install poetry
  - uses: actions/setup-python@v3
    with:
      python-version: "3.10"
      cache: "poetry"
  - run: poetry install
  - name: Run tests
    run: |
      make mypy
      make test
The pyproject.toml specifies Python 3.10 as well:
[tool.poetry.dependencies]
python = ">=3.10,<3.11"
When the action runs, I get the following:
The currently activated Python version 3.8.10 is not supported by the project 
(>=3.10,<3.11).
Trying to find and use a compatible version. 
Using python3 (3.10.5)
It would look like it's using 3.10, but py.test is using 3.8.10:
platform linux -- Python 3.8.10, pytest-6.2.5, py-1.11.0, pluggy-1.0.0 -- 
/home/runner/.cache/pypoetry/virtualenvs/vital-background-pull-yluVa_Vi-py3.10/bin/python
For context, this Github action was running on 3.8 before. I've updated the python version in both the test.yaml and the pyproject.toml but it's still using 3.8. Anything else I should change to make it use 3.10?
Thank you
The root cause is the section
- uses: actions/setup-python@v3
  with:
    python-version: "3.10"
    cache: "poetry"
with the line caching poetry. Since poetry was previously installed with a pip associated with Python 3.8, the package will be retrieved from the cache associated with that Python version. It needs to be re-installed with the new Python version.
You can either remove the cache: poetry from a single GH actions execution, or remove the cache manually. This will fix your issue.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With