|
| 1 | +# Python package |
| 2 | +# Create and test a Python package on multiple Python versions. |
| 3 | +# Add steps that analyze code, save the dist with the build record, publish to a PyPI-compatible index, and more: |
| 4 | +# https://docs.microsoft.com/vsts/pipelines/languages/python |
| 5 | + |
| 6 | +jobs: |
| 7 | + |
| 8 | +- job: 'Test' |
| 9 | + |
| 10 | + # Configure Build Environment to use Azure Pipelines to build Python project using macOS |
| 11 | + pool: |
| 12 | + vmImage: 'macOS 10.13' # other options 'Ubuntu 16.04', 'VS2017-Win2016' |
| 13 | + |
| 14 | + # Run the pipeline with multiple Python versions |
| 15 | + strategy: |
| 16 | + matrix: |
| 17 | + Python34: |
| 18 | + python.version: '3.4' |
| 19 | + Python35: |
| 20 | + python.version: '3.5' |
| 21 | + Python36: |
| 22 | + python.version: '3.6' |
| 23 | + Python37: |
| 24 | + python.version: '3.7' |
| 25 | + # Increase the maxParallel value to simultaneously run the job for all versions in the matrix (max 10 for free open-source) |
| 26 | + maxParallel: 4 |
| 27 | + |
| 28 | + steps: |
| 29 | + # Set the UsePythonVersion task to reference the matrix variable for its Python version |
| 30 | + - task: UsePythonVersion@0 |
| 31 | + inputs: |
| 32 | + versionSpec: '$(python.version)' |
| 33 | + architecture: 'x64' |
| 34 | + |
| 35 | + # Install dependencies - install specific PyPI packages with pip, including cmd2 dependencies |
| 36 | + - script: | |
| 37 | + python -m pip install --upgrade pip && pip3 install --upgrade setuptools gnureadline |
| 38 | + pip install -e . |
| 39 | + displayName: 'Upgrade pip and setuptools' |
| 40 | + continueOnError: false |
| 41 | +
|
| 42 | + # TODO: Consider adding a lint test to use pycodestyle, flake8, or pylint, to check code style conventions |
| 43 | +
|
| 44 | + # Test - test with pytest, collect coverage metrics with pytest-cov, and publish these metrics to codecov.io |
| 45 | + - script: | |
| 46 | + pip install pytest pytest-cov pytest-mock codecov mock |
| 47 | + py.test tests --cov --junitxml=junit/test-results.xml && codecov |
| 48 | + displayName: 'Run tests and code coverage' |
| 49 | + continueOnError: false |
| 50 | +
|
| 51 | + # Publish test results to the Azure DevOps server |
| 52 | + - task: PublishTestResults@2 |
| 53 | + inputs: |
| 54 | + testResultsFiles: '**/test-*.xml' |
| 55 | + testRunTitle: 'Python $(python.version)' |
| 56 | + condition: succeededOrFailed() |
0 commit comments