Python

venv

In check() part, setup venv and use python from there:

python3 -m venv --clear --system-site-packages .testenv
.testenv/bin/python3 -m installer xxx.whl
.testenv/bin/python3 -m pytest

PATH

Export $PATH if needed (some test call binrary)

export PATH="$builddir"/.testenv/bin:$PATH

Be careful that all runpart check() and package() are in the same process sharing same environment.

pip

By default, pip install source files within "another" isolation, but we usually want to use packages from system and build():

.testenv/bin/python3 -m pip install --no-build-isolation --no-index xxx