Newsletter
TechAnV Blog
Get updates on security engineering, Rust, eBPF, and DevSecOps. No spam, unsubscribe anytime.
Check your inbox and click the confirmation link to complete your subscription.
Quickly testing code in a different Python version using pyenv#
I had a bug that was only showing up in CI against Python 3.8.
I used the following pattern with pyenv to quickly run the tests against that specific version.
(I had previously installed pyenv using brew install pyenv.)
Seeing what versions I had already#
1pyenv versionsThis outputs (on my machine):
1 system2 3.7.163 3.8.17To see all possible versions:
1pyenv install --listThat’s a long list! I grepped it for 3.8:
1pyenv install --list | grep '3.8'1 3.8.02 3.8-dev3 3.8.14 3.8.25 ...6 3.8.147 3.8.158 3.8.169 3.8.1710 ...Installing a specific version#
I installed 3.8.17 like this:
1pyenv install 3.8.17This took a long time, because it compiled it from scratch.
Using that version via a virtual environment#
I decided to use that version of Python directly. The binary was installed here:
1~/.pyenv/versions/3.8.17/bin/pythonI created a temporary virtual environment in /tmp like this:
1~/.pyenv/versions/3.8.17/bin/python -m venv /tmp/py38envThen installed my current project into that environment like so:
1/tmp/py38env/bin/pip install -e '.[test]'Now I can run the tests like this:
1/tmp/py38env/bin/pytest