Skip to content

Instantly share code, notes, and snippets.

@etiennepouliot
Created February 10, 2022 13:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save etiennepouliot/acc4ab7f30a9c73434e6f15aa45fffcb to your computer and use it in GitHub Desktop.
Save etiennepouliot/acc4ab7f30a9c73434e6f15aa45fffcb to your computer and use it in GitHub Desktop.
Azure Pipeline to test Django with MySQL and Python 3.9

Azure Pipeline file

Goals

I wanted a pipeline that would test django. Since I use some the special field of MySQL (https://django-mysql.readthedocs.io/en/latest/model_fields/index.html), I needed a MySQL database.

Hardest part was that the Ubuntu 20.04 vm is stripped down. Systemd does not appear to work, so I couldn't start MySQL. I hard to manually start MySQL.

As well, I wanted to test with Python3.9 wich is the version that I use for my project.

trigger:
- master
pool:
name: 'Linux'
steps:
- script: |
apt-get -qq -y update
apt-get -qq -y install software-properties-common
apt-get -qq -y install mysql-server libmysqlclient-dev libxmlsec1-openssl libxmlsec1-dev pkg-config
add-apt-repository -y ppa:deadsnakes/ppa
apt-get -qq -y install python3.9 python3.9-dev
displayName: 'Install Mysql and python 3.9'
- script: |
/usr/bin/install -m 755 -o mysql -g root -d /var/run/mysqld
nohup mysqld_safe --socket=/tmp/mysql.sock --skip-networking --skip-mysqlx &
displayName: 'start mysql'
- script: |
python3.9 -m pip install --upgrade pip setuptools wheel
pip3 install -r requirements.txt
pip3 install unittest-xml-reporting requests-mock
displayName: 'Install prerequisites'
- task: PythonScript@0
displayName: 'Export project path'
inputs:
scriptSource: 'inline'
pythonInterpreter: '/bin/python3.9'
script: |
"""Search all subdirectories for `manage.py`."""
from glob import iglob
from os import path
# Python >= 3.5
manage_py = next(iglob(path.join('**', 'manage.py'), recursive=True), None)
if not manage_py:
raise SystemExit('Could not find a Django project')
project_location = path.dirname(path.abspath(manage_py))
print('Found Django project in', project_location)
print('##vso[task.setvariable variable=projectRoot]{}'.format(project_location))
- script: |
pushd '$(projectRoot)'
python3.9 manage.py test --testrunner xmlrunner.extra.djangotestrunner.XMLTestRunner --no-input --parallel 1
displayName: 'Run tests'
continueOnError: true
- task: PublishTestResults@2
inputs:
testResultsFiles: "**/TEST-*.xml"
testRunTitle: 'Python $(PYTHON_VERSION)'
condition: succeededOrFailed()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment