AWS provides support for installing python 3.11 in Amazon Linux 2023 containers.
However it isn't at all obvious how you install and run a compatible pytest in this case.
For example, if you do this:
dnf install -y pytest
the version of pytest installed is the 3.9 version which is compatible with the so-called system version of Python which is 3.9 but is not compatible with python3.11 installed via the supported method.
So what is the canonical way for installing a version of pytest which is compatible with the python3.11 as installed in the manner recommended by AWS?
The best way is probably to set up a 3.11 virtual environment and install pytest into that environment:
Now running
pytest
gets youpytest
for Python 3.11. You will of course want to install any other dependencies into the virtual environment; a common setup is to put runtime dependencies inrequirements.txt
and test requirements (like pytest) intotest-requirements.txt
, so that you setup process looks like:Alternately, you can install a version of
pip
to go along with yourpython3.11
install:And then globally install pytest using
pip
:But as the warning says, installing things globally like this can lead to conflicts.