Skip to content

Commit 5d22e46

Browse files
committed
Fixups regarding Code Coverage
1 parent a5c32bc commit 5d22e46

File tree

7 files changed

+70
-74
lines changed

7 files changed

+70
-74
lines changed

.coveragerc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
# agreement to the Shotgun Pipeline Toolkit Source Code License. All rights
99
# not expressly granted therein are reserved by Shotgun Software Inc.
1010
#
11-
# coverage configuration - used by https://coveralls.io/ integration
11+
# coverage configuration - used by pytest-cov and codecov.io integration
1212
#
1313
#
1414

1515
[run]
1616
source=shotgun_api3
1717
omit=
1818
shotgun_api3/lib/httplib2/*
19-
shotgun_api3/lib/certify/*
19+
shotgun_api3/lib/certifi/*
2020
shotgun_api3/lib/pyparsing.py

README.md

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
[![Reference Documentation](http://img.shields.io/badge/Reference-documentation-blue.svg?logo=wikibooks&logoColor=f5f5f5)](http://developer.shotgridsoftware.com/python-api)
33

44
[![Build Status](https://dev.azure.com/shotgun-ecosystem/Python%20API/_apis/build/status/shotgunsoftware.python-api?branchName=master)](https://dev.azure.com/shotgun-ecosystem/Python%20API/_build/latest?definitionId=108&branchName=master)
5-
[![Coverage Status](https://coveralls.io/repos/github/shotgunsoftware/python-api/badge.svg?branch=master)](https://coveralls.io/github/shotgunsoftware/python-api?branch=master)
5+
[![Coverage Status](https://codecov.io/gh/shotgunsoftware/python-api/branch/master/graph/badge.svg)](https://codecov.io/gh/shotgunsoftware/python-api)
66

77
# Flow Production Tracking Python API
88

@@ -11,7 +11,7 @@ Autodesk provides a simple Python-based API for accessing Flow Production Tracki
1111
The latest version can always be found at https://github.com/shotgunsoftware/python-api
1212

1313
## Documentation
14-
Tutorials and detailed documentation about the Python API are available at http://developer.shotgridsoftware.com/python-api).
14+
Tutorials and detailed documentation about the Python API are available at http://developer.shotgridsoftware.com/python-api.
1515

1616
Some useful direct links:
1717

@@ -31,12 +31,11 @@ You can see the [full history of the Python API on the documentation site](http:
3131
Integration and unit tests are provided.
3232

3333
- All tests require:
34-
- The [nose unit testing tools](http://nose.readthedocs.org),
35-
- The [nose-exclude nose plugin](https://pypi.org/project/nose-exclude/)
36-
- (Note: Running `pip install -r tests/ci_requirements.txt` will install this package)
34+
- [pytest](https://docs.pytest.org/) and related plugins
35+
- (Note: Running `pip install -r tests/requirements.txt` will install all required packages)
3736
- A `tests/config` file (you can copy an example from `tests/example_config`).
38-
- Tests can be run individually like this: `nosetests --config="nose.cfg" tests/test_client.py`
39-
- Make sure to not forget the `--config="nose.cfg"` option. This option tells nose to use our config file.
40-
- `test_client` and `tests_unit` use mock server interaction and do not require a Flow Production Tracking instance to be available (no modifications to `tests/config` are necessary).
37+
- Tests can be run individually like this: `pytest tests/test_client.py`
38+
- To run all tests: `pytest`
39+
- To run tests with coverage: `pytest --cov shotgun_api3 --cov-report html`
40+
- `test_client` and `test_unit` use mock server interaction and do not require a Flow Production Tracking instance to be available (no modifications to `tests/config` are necessary).
4141
- `test_api` and `test_api_long` *do* require a Flow Production Tracking instance, with a script key available for the tests. The server and script user values must be supplied in the `tests/config` file. The tests will add test data to your server based on information in your config. This data will be manipulated by the tests, and should not be used for other purposes.
42-
- To run all of the tests, use the shell script `run-tests`.

azure-pipelines-templates/run-tests.yml

Lines changed: 45 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,17 @@
2828

2929
# This is the list of parameters for this template and their default values.
3030
parameters:
31-
os_name: ''
32-
vm_image: ''
33-
python_version: ''
31+
- name: codecov_download_url
32+
type: string
33+
34+
- name: os_name
35+
type: string
36+
37+
- name: python_version
38+
type: string
39+
40+
- name: vm_image
41+
type: string
3442

3543
jobs:
3644
# The job will be named after the OS and Azure will suffix the strategy to make it unique
@@ -63,7 +71,7 @@ jobs:
6371
script: |
6472
pip install --upgrade pip
6573
pip install --upgrade setuptools wheel
66-
pip install --upgrade --requirement tests/ci_requirements.txt
74+
pip install --upgrade --requirement tests/requirements.txt
6775
6876
# The {{}} syntax is meant for the the pre-processor of Azure pipeline. Every statement inside
6977
# a {{}} block will be evaluated and substituted before the file is parsed to create the jobs.
@@ -79,18 +87,18 @@ jobs:
7987
Import-Certificate -FilePath $cert_file.FullName -CertStoreLocation Cert:\LocalMachine\Root
8088
displayName: Updating OS Certificates
8189
82-
# Runs the tests and generates test coverage. The tests results are uploaded to Azure Pipelines in the
83-
# Tests tab of the build and each test run will be named after the --test-run-title argument to pytest,
84-
# for example 'Windows - 2.7'
90+
# Runs the tests and generates both test report and code coverage
8591
- task: Bash@3
8692
displayName: Running tests
8793
inputs:
8894
targetType: inline
8995
script: |
9096
cp ./tests/example_config ./tests/config
91-
pytest --durations=0 -v \
92-
--cov shotgun_api3 --cov-report xml \
93-
--test-run-title="${{ parameters.os_name }}-${{ parameters.python_version }}"
97+
python -m pytest \
98+
--verbose \
99+
--nunit-xml=test-results.xml \
100+
--cov \
101+
--cov-report xml \
94102
env:
95103
# Pass the values needed to authenticate with the Flow Production Tracking site and create some entities.
96104
# Remember, on a pull request from a client or on forked repos, those variables
@@ -124,22 +132,31 @@ jobs:
124132
SG_TASK_CONTENT: CI-$(python_api_human_login)-${{ parameters.os_name }}-${{ parameters.python_version }}
125133
SG_PLAYLIST_CODE: CI-$(python_api_human_login)-${{ parameters.os_name }}-${{ parameters.python_version }}
126134

127-
# Upload the code coverage result to codecov.io.
128-
- ${{ if eq(parameters.os_name, 'Windows') }}:
129-
- powershell: |
130-
$ProgressPreference = 'SilentlyContinue'
131-
Invoke-WebRequest -Uri https://uploader.codecov.io/latest/windows/codecov.exe -Outfile codecov.exe
132-
.\codecov.exe -f coverage.xml
133-
displayName: Uploading code coverage
134-
- ${{ elseif eq(parameters.os_name, 'Linux') }}:
135-
- script: |
136-
curl -Os https://uploader.codecov.io/latest/linux/codecov
137-
chmod +x codecov
138-
./codecov -f coverage.xml
139-
displayName: Uploading code coverage
140-
- ${{ else }}:
141-
- script: |
142-
curl -Os https://uploader.codecov.io/v0.7.3/macos/codecov
135+
- task: PublishTestResults@2
136+
displayName: Publish test results
137+
inputs:
138+
testResultsFormat: NUnit
139+
testResultsFiles: test-results.xml
140+
testRunTitle: "${{ parameters.os_name }} - Python ${{ parameters.python_version }}"
141+
failTaskOnFailureToPublishResults: true
142+
failTaskOnMissingResultsFile: true
143+
condition: succeededOrFailed()
144+
145+
- task: PublishCodeCoverageResults@2
146+
displayName: Publish code coverage
147+
inputs:
148+
summaryFileLocation: coverage.xml
149+
failIfCoverageEmpty: true
150+
151+
- task: Bash@3
152+
displayName: Uploading coverage to Codecov.io
153+
inputs:
154+
targetType: inline
155+
script: |
156+
curl -Os "${{ parameters.codecov_download_url }}"
143157
chmod +x codecov
144-
./codecov -f coverage.xml
145-
displayName: Uploading code coverage
158+
./codecov \
159+
--file coverage.xml \
160+
--flags ${{ parameters.os_name }} \
161+
--flags "Python ${{ parameters.python_version }}" \
162+
--name "Tests ran on ${{ parameters.os_name }} with Python ${{ parameters.python_version }}" \

azure-pipelines.yml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,21 @@ parameters:
7272
default:
7373
- name: Linux
7474
vm_image: ubuntu-latest
75+
codecov_download_url: https://uploader.codecov.io/latest/linux/codecov
7576

7677
- name: macOS
7778
vm_image: macOS-latest
79+
codecov_download_url: https://uploader.codecov.io/v0.7.3/macos/codecov
80+
# macOS & codecov note:
81+
# In Nov 2024 (SG-36700), we pinned macOS to codecov v0.7.3 because the
82+
# macOS-latest Azure Pipelines agent is Intel (x86_64), but Codecov
83+
# started shipping arm64-only binaries.
84+
# When we will change the macOs image to a arm64 arch, we can use the
85+
# "latest" version again.
7886

7987
- name: Windows
8088
vm_image: windows-latest
89+
codecov_download_url: https://uploader.codecov.io/latest/windows/codecov.exe
8190

8291
# This here is the list of jobs we want to run for our build.
8392
# Jobs run in parallel.
@@ -96,6 +105,7 @@ jobs:
96105
- ${{ each python_version in parameters.python_versions }}:
97106
- template: azure-pipelines-templates/run-tests.yml
98107
parameters:
99-
os_name: "${{ os_version.name }}"
100-
vm_image: ${{ os_version.vm_image }}
108+
codecov_download_url: ${{ os_version.codecov_download_url }}
109+
os_name: ${{ os_version.name }}
101110
python_version: ${{ python_version }}
111+
vm_image: ${{ os_version.vm_image }}

run-tests

Lines changed: 0 additions & 13 deletions
This file was deleted.

tests/ci_requirements.txt

Lines changed: 0 additions & 18 deletions
This file was deleted.

nose.cfg renamed to tests/requirements.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@
88
# agreement to the Shotgun Pipeline Toolkit Source Code License. All rights
99
# not expressly granted therein are reserved by Shotgun Software Inc.
1010

11-
[nosetests]
12-
exclude-dir=shotgun_api3/lib
11+
pytest
12+
pytest-cov
13+
pytest-nunit

0 commit comments

Comments
 (0)