Skip to content

Commit 1fb626f

Browse files
authored
SG-38126 Review and Fixups CI Tests and Code Coverage (#439)
* Fixups regarding Code Coverage * Black update + durations
1 parent a5c32bc commit 1fb626f

File tree

12 files changed

+95
-91
lines changed

12 files changed

+95
-91
lines changed

.coveragerc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,12 @@
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
12-
#
11+
# coverage.py configuration (https://pypi.org/project/coverage/)
1312
#
1413

1514
[run]
1615
source=shotgun_api3
1716
omit=
1817
shotgun_api3/lib/httplib2/*
19-
shotgun_api3/lib/certify/*
18+
shotgun_api3/lib/certifi/*
2019
shotgun_api3/lib/pyparsing.py

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ exclude: "shotgun_api3/lib/.*"
3333
# List of super useful formatters.
3434
repos:
3535
- repo: https://github.com/pre-commit/pre-commit-hooks
36-
rev: v5.0.0
36+
rev: v6.0.0
3737
hooks:
3838
- id: check-ast
3939
- id: check-case-conflict
@@ -44,6 +44,6 @@ repos:
4444
- id: trailing-whitespace
4545

4646
- repo: https://github.com/psf/black
47-
rev: 25.1.0
47+
rev: 26.1.0
4848
hooks:
4949
- id: black

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: 63 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,26 @@
2626
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2727
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2828

29-
# This is the list of parameters for this template and their default values.
3029
parameters:
31-
os_name: ''
32-
vm_image: ''
33-
python_version: ''
30+
# Using the most formal way of defining parameters so we don't define a
31+
# default value for mandatory parameters. This way, CI will fail if we forget
32+
# to pass it when invoking the template.
33+
34+
- name: codecov_download_url
35+
type: string
36+
37+
- name: os_name
38+
type: string
39+
40+
- name: python_version
41+
type: string
42+
43+
- name: vm_image
44+
type: string
3445

3546
jobs:
36-
# The job will be named after the OS and Azure will suffix the strategy to make it unique
37-
# so we'll have a job name "Windows Python 3.9" for example. What's a strategy? Strategies are the
38-
# name of the keys under the strategy.matrix scope. So for each OS we'll have "<OS> Python 3.9" and
39-
# "<OS> Python 3.10".
4047
- job:
41-
displayName: "${{ parameters.os_name }} Python ${{ parameters.python_version }}"
48+
displayName: "${{ parameters.os_name }} - Python ${{ parameters.python_version }}"
4249
pool:
4350
vmImage: ${{ parameters.vm_image }}
4451

@@ -61,9 +68,10 @@ jobs:
6168
inputs:
6269
targetType: inline
6370
script: |
71+
set -e
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,19 +87,24 @@ 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: |
96+
set -e
9097
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 }}"
98+
python -m pytest \
99+
--cov \
100+
--cov-report xml:coverage.xml \
101+
--durations=0 \
102+
--nunit-xml=test-results.xml \
103+
--verbose \
94104
env:
105+
# Tell Pytest that we're running in a CI environment
106+
CI: 1
107+
95108
# Pass the values needed to authenticate with the Flow Production Tracking site and create some entities.
96109
# Remember, on a pull request from a client or on forked repos, those variables
97110
# will be empty!
@@ -124,22 +137,38 @@ jobs:
124137
SG_TASK_CONTENT: CI-$(python_api_human_login)-${{ parameters.os_name }}-${{ parameters.python_version }}
125138
SG_PLAYLIST_CODE: CI-$(python_api_human_login)-${{ parameters.os_name }}-${{ parameters.python_version }}
126139

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
140+
# Explicit call to PublishTestResults@2 and PublishCodeCoverageResults@2 here
141+
# instead of relying on pytest-azurepipelines because pytest-azurepipelines
142+
# does not seem to be maintained anymore and is still using earlier versions
143+
# of the PublishTestResults and PublishCodeCoverageResults Azure Pipelines
144+
# jobs.
145+
146+
- task: PublishTestResults@2
147+
displayName: Publish test results
148+
inputs:
149+
failTaskOnFailureToPublishResults: true
150+
failTaskOnMissingResultsFile: true
151+
testResultsFiles: test-results.xml
152+
testResultsFormat: NUnit
153+
testRunTitle: "${{ parameters.os_name }} - Python ${{ parameters.python_version }}"
154+
condition: succeededOrFailed()
155+
156+
- task: PublishCodeCoverageResults@2
157+
displayName: Publish code coverage
158+
inputs:
159+
summaryFileLocation: coverage.xml
160+
failIfCoverageEmpty: true
161+
162+
- task: Bash@3
163+
displayName: Uploading coverage to Codecov.io
164+
inputs:
165+
targetType: inline
166+
script: |
167+
set -e
168+
curl --remote-name --silent "${{ parameters.codecov_download_url }}"
143169
chmod +x codecov
144-
./codecov -f coverage.xml
145-
displayName: Uploading code coverage
170+
./codecov \
171+
--file coverage.xml \
172+
--flags "${{ parameters.os_name }}" \
173+
--flags "Python-${{ parameters.python_version }}" \
174+
--name "Tested 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.

shotgun_api3/shotgun.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@
7171
from .lib.httplib2 import Http, ProxyInfo, socks
7272
from .lib.sgtimezone import SgTimezone
7373

74-
7574
LOG = logging.getLogger("shotgun_api3")
7675
"""
7776
Logging instance for shotgun_api3

tests/base.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import shotgun_api3 as api
1515
from shotgun_api3.shotgun import ServerCapabilities
1616

17-
1817
THUMBNAIL_MAX_ATTEMPTS = 30
1918
THUMBNAIL_RETRY_INTERVAL = 10
2019
TRANSIENT_IMAGE_PATH = "images/status/transient"

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)