Python3 is here

The switch to Python3 for the Asterisk tesuite has been released!  Previous blog posts have gone over some of the internal changes that have been required but now that its actually here, what does this mean for those of us who use and depend upon it?

First, to get it out of the way – Python2 is no longer supported with this change.  If you want to continue to run the current Asterisk Testsuite this will require a minimum of Python 3.6.8.

If you are using the runTestsuite.sh script in Asterisk and have asterisk 3.6.8 or later installed on Centos7 or later then you can continue to do so pretty much as-is.  However, internally this script now creates and uses a Python virtual environment (venv) to download and install the Testsuite Python requirements.  This keeps the package dependencies consistent and allows you to run the Asterisk Testsuite separately from your host os’s Python environment.  The script will re-use the environment if already created to cache the requirements.  If you invoke the runTestsuite.sh script from inside an existing virtual environment, then it will use that virtual environment as-is.  This is in case your installation has certain specific requirements that need to be over-written or if you want to test other package versions.

If you run the Testsuite manually via runtests.py you are not required to do so from within a virtual environment.  The Testsuite does now include some things to make running inside a venv easier.  To that end, the .gitignore now includes a .venv directory and the Testsuite itself includes the required version info required to set it up.  The Python package requirements are stored in two files in the root directory of the Testsuite: requirements.txt and extras.txt.  The first, requirements.txt lists the pip package requirements for Python3.  The second, extras.txt installs starpy and yappcap from Asterisk sources on github.  These can be used inside as well as outside of a virtual environment.

To create and set up the virtual environment, run the following from the Testsuite root directory:

> python3 -m venv .venv
> source .venv/bin/activate
> python -m pip install --upgrade pip
> python -m pip install wheel setuptools build
> python -m pip install -r ./requirements.txt
> python -m pip install -r ./extras.txt

From here, you can use runtests.py and cleanup-test-remnants.sh per usual.  Once you are done, a call to deactivate will exit from the virtual environment.  If you are running a test as root from the activated virtual environment, you may need to specify PATH manually, ie:

> sudo -E env PATH=$PATH ./runtests.py -t tests/channels/pjsip 

If you are going to run the Testsuite from inside a Docker container, it is simpler to use the runTestsuite.sh than to try and set up the Python environment manually.  This is due to the way multiple run commands each launch in separate shells, so you can’t activate and run within the same command.  There are some ways to get around this and in our case we do so by activating and running within the same script.

So, there it is.  Hopefully the install and run process is a bit easier now and a bit more stable.  There are a handful of tests that need to be upgraded so keep a look out for more improvements!

About the Author

What can we help you find?