Skip to content

Commit

Permalink
check-py-ver: Confirm each tox environment is using correct Python ve…
Browse files Browse the repository at this point in the history
…rsion
  • Loading branch information
0cjs committed Jan 17, 2024
1 parent f507846 commit df93141
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
29 changes: 29 additions & 0 deletions check-py-ver
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env bash
#
# check-py-ver - confirm Python seems right for the tox environment
#
# Bad/missing `base_python` settings can cause tox to quietly use tox's
# Python version rather than one matching the py* factor in the
# environment name. For example, if in `[testenv]` you specify
# `base_python = py3.8: ...`, that leaves `base_python` unset for a tox
# environment with factor `py3.9`. This will cause tox to create or even
# change the py3.9 environment to use e.g. Python 3.11 (if that's what
# tox itself is using) instead of 3.9 and carry on as if everything is ok.
#
# Calling this script at the start of `commands = ...` allows us to
# ensure that, even with possibly subtle configuration errors, we really
# are using the Python version matching the py* factor in the environment
# name.
#

pyver=py$(python -c '
import sys
vi = sys.version_info
print("{}.{}".format(vi.major, vi.minor))
')

[[ ${TOX_ENV_NAME%%-*} == $pyver ]] || {
echo 1>&2 "check-py-ver:" \
"Python version $pyver does not match environment ${TOX_ENV_NAME}"
exit 5
}
2 changes: 2 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ deps =
pytest5: pytest==5.*
pytest6: pytest==6.*
pytest7: pytest==7.*
allowlist_externals = ./check-py-ver
commands =
# pytest will fail if there are no tests to run. Thus, using -k
# separately on both the one test from *.pt and the one test from
# *_test.py will ensure that both tests are being collected and run.
./check-py-ver
pytest -qq pylib/ -k pt_test {posargs}
pytest -qq pylib/ -k regular_test {posargs}

Expand Down

0 comments on commit df93141

Please sign in to comment.