Python 3.12.0a2 is out. So now may be a great time to get your projects to start testing against 3.12.

Note about alpha releases of Python

This is from the same link as above: “During the alpha phase, features may be added up until the start of the beta phase (2023-05-08) and, if necessary, may be modified or deleted up until the release candidate phase (2023-07-31). Please keep in mind that this is a preview release and its use is not recommended for production environments.”

So. Keep that in mind.

But for my Python package projects, like pytest-check, for instance, I want to know ASAP if something is amiss with running on Python 3.12, so I’m going for it.

If you decide to update now

What does that mean?

Many of my projects utilize tox for local testing and GitHub Actions for CI testing. And I’d like to proactively test against 3.12 now, before it’s stressful.

Even though 3.12 is at the Alpha2 phase, it’s not planned on being released until Oct 2, 2023, it’s not too early to set up your testing and be ready.

My steps:

1. Download Python 3.12

Now 3.12a2, but I’ll try to keep track of alpha and beta releases and update accordingly. Download 3 .12a2 here.

2. Try running Python 3.12a2 with py

I love having py, the Python launcher, installed on my Mac. It let’s me run Python 3.12 with a py --3.12.

3. Update tox.ini for Python 3.12

I’ve already got a envlist that looks something like this:

envlist = py37, py38, py39, py310, py311, coverage, flake8

I just expand it with py312:

envlist = py37, py38, py39, py310, py311, py312, coverage, flake8

Then run tox and see the pytest goodness:

  py37: commands succeeded
  py310: commands succeeded
  py311: commands succeeded
  py312: commands succeeded
  coverage: commands succeeded
  flake8: commands succeeded
  congratulations :)

4. Update GitHub Actions to test with Python 3.12

My test matrix in .github/workflows/main.yml are usually pretty simple:

    runs-on: ubuntu-latest
        python: ["3.7", "3.8", "3.9", "3.10", "3.11"]

I just extended the list with 3.12-dev:

    runs-on: ubuntu-latest
        python: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12-dev"]

5. Push to GitHub

Now commit & push and watch the fun.

Example code

I’ve just made these changes to the pytest-check pytest plugin. See PR 106

What if 3.12 fails, but I don’t want my pipeline to stop?

There’s a section of the GitHub Actions docs on handling failures.

If we want to set py3.12-dev to allow failures, we can use continue-on-error. I’ve tried this and set it up kinda like the GH docs example.

Note that the term “experimental” doesn’t matter, I don’t think. We could have used “foo” or “let-this-one-fail”. But “experimental” does seem appropriate, so I kept it.

    runs-on: ubuntu-latest
    continue-on-error: ${{ matrix.experimental }}
        python: ["3.7", "3.8", "3.9", "3.10", "3.11"]
        experimental: [false]
        - python: "3.12-dev"
          experimental: true

This can be seen in PR 107.


  • Thanks @btskinn and @hugovk for the question and solution about allowing 3.12-dev workflows to fail.
  • Thanks Brett Cannon for python-launcher, that allows me to use py on my Mac.
  • Thanks to whoever is making sure py3.12-dev works on GitHub Actions. Super awesome.
  • And of course thank you to everyone working on Python 3.12.