Skip to content

Commit 1f60cda

Browse files
authored
Improving CI for running tests (#322)
* Fixing CI * just keep master branch in the workflow * Refactors based on PR comments * tox accepts only 1 dep per line * fixing some deps * fixing some deps * fixing some deps * pinning pytest-aiohttp dep version
1 parent 71436ad commit 1f60cda

File tree

6 files changed

+193
-104
lines changed

6 files changed

+193
-104
lines changed

.github/workflows/UnitTesting.yaml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: Unit Testing
2+
on:
3+
push:
4+
branches:
5+
- master
6+
pull_request:
7+
branches:
8+
- master
9+
10+
jobs:
11+
test:
12+
# "setup-python" action doesn't provide python 3.4 binaries for ubuntu-latest.
13+
# Sticking to Ubuntu 18.04 as recommended here:
14+
# https://github.com/actions/setup-python/issues/185#issuecomment-768232756
15+
runs-on: ubuntu-18.04
16+
env:
17+
py27: 2.7
18+
py34: 3.4
19+
py35: 3.5
20+
py36: 3.6
21+
py37: 3.7
22+
py38: 3.8
23+
py39: 3.9
24+
strategy:
25+
fail-fast: false
26+
matrix:
27+
python-version: [py27, py34, py35, py36, py37, py38, py39]
28+
testenv: [core, ext]
29+
steps:
30+
- name: Checkout repo
31+
uses: actions/checkout@v2
32+
33+
- name: Setup Python
34+
uses: actions/setup-python@v2
35+
with:
36+
python-version: ${{ env[matrix.python-version] }}
37+
38+
- name: Install tox
39+
run: pip install -U tox-factor
40+
41+
- name: Cache tox environment
42+
# Preserves .tox directory between runs for faster installs
43+
uses: actions/cache@v2
44+
with:
45+
path: |
46+
.tox
47+
~/.cache/pip
48+
key: tox-cache-${{ matrix.python-version }}-${{ matrix.testenv }}-${{ hashFiles('tox.ini') }}
49+
50+
- name: Run tox
51+
run: |
52+
tox -f ${{ matrix.python-version }}-${{ matrix.testenv }}

aws_xray_sdk/core/sampling/local/sampler.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
from .sampling_rule import SamplingRule
66
from ...exceptions.exceptions import InvalidSamplingManifestError
77

8-
local_sampling_rule = json.loads(pkgutil.get_data(__name__, 'sampling_rule.json'))
8+
# `.decode('utf-8')` needed for Python 3.4, 3.5.
9+
local_sampling_rule = json.loads(pkgutil.get_data(__name__, 'sampling_rule.json').decode('utf-8'))
910

1011
SUPPORTED_RULE_VERSION = (1, 2)
1112

aws_xray_sdk/ext/boto_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111

1212
from aws_xray_sdk.ext.util import inject_trace_header, to_snake_case
1313

14-
15-
whitelist = json.loads(pkgutil.get_data(__name__, 'resources/aws_para_whitelist.json'))
14+
# `.decode('utf-8')` needed for Python 3.4, 3.5
15+
whitelist = json.loads(pkgutil.get_data(__name__, 'resources/aws_para_whitelist.json').decode('utf-8'))
1616

1717

1818
def inject_header(wrapped, instance, args, kwargs):

tests/ext/aiobotocore/test_aiobotocore.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import pytest
22

3-
import aiobotocore
3+
from aiobotocore.session import get_session
44
from botocore.stub import Stubber, ANY
55
from botocore.exceptions import ClientError
66

@@ -28,7 +28,7 @@ async def test_describe_table(loop, recorder):
2828
req_id = '1234'
2929
response = {'ResponseMetadata': {'RequestId': req_id, 'HTTPStatusCode': 403}}
3030

31-
session = aiobotocore.get_session()
31+
session = get_session()
3232
async with session.create_client('dynamodb', region_name='eu-west-2') as client:
3333
with Stubber(client) as stubber:
3434
stubber.add_response('describe_table', response, {'TableName': 'mytable'})
@@ -53,7 +53,7 @@ async def test_s3_parameter_capture(loop, recorder):
5353
version_id = 'myversionid'
5454
response = {'ResponseMetadata': {'RequestId': '1234', 'HTTPStatusCode': 200}}
5555

56-
session = aiobotocore.get_session()
56+
session = get_session()
5757
async with session.create_client('s3', region_name='eu-west-2') as client:
5858
with Stubber(client) as stubber:
5959
stubber.add_response('get_object', response,
@@ -87,7 +87,7 @@ async def test_list_parameter_counting(loop, recorder):
8787
}
8888
}
8989

90-
session = aiobotocore.get_session()
90+
session = get_session()
9191
async with session.create_client('sqs', region_name='eu-west-2') as client:
9292
with Stubber(client) as stubber:
9393
stubber.add_response('list_queues', response, {'QueueNamePrefix': queue_name_prefix})
@@ -117,7 +117,7 @@ async def test_map_parameter_grouping(loop, recorder):
117117
}
118118
}
119119

120-
session = aiobotocore.get_session()
120+
session = get_session()
121121
async with session.create_client('dynamodb', region_name='eu-west-2') as client:
122122
with Stubber(client) as stubber:
123123
stubber.add_response('batch_write_item', response, {'RequestItems': ANY})
@@ -137,7 +137,7 @@ async def test_context_missing_not_swallow_return(loop, recorder):
137137

138138
response = {'ResponseMetadata': {'RequestId': '1234', 'HTTPStatusCode': 403}}
139139

140-
session = aiobotocore.get_session()
140+
session = get_session()
141141
async with session.create_client('dynamodb', region_name='eu-west-2') as client:
142142
with Stubber(client) as stubber:
143143
stubber.add_response('describe_table', response, {'TableName': 'mytable'})
@@ -150,7 +150,7 @@ async def test_context_missing_not_suppress_exception(loop, recorder):
150150
xray_recorder.configure(service='test', sampling=False,
151151
context=AsyncContext(loop=loop), context_missing='LOG_ERROR')
152152

153-
session = aiobotocore.get_session()
153+
session = get_session()
154154
async with session.create_client('dynamodb', region_name='eu-west-2') as client:
155155
with Stubber(client) as stubber:
156156
stubber.add_client_error('describe_table', expected_params={'TableName': ANY})

tests/test_local_sampling_benchmark.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
# Faster
66
def test_pkgutil_static_read(benchmark):
77
def get_sampling_rule():
8-
return json.loads(pkgutil.get_data(__name__, 'mock_sampling_rule.json'))
8+
# `.decode('utf-8')` needed for Python 3.4, 3.5
9+
return json.loads(pkgutil.get_data(__name__, 'mock_sampling_rule.json').decode('utf-8'))
910
benchmark(get_sampling_rule)
1011

1112
# Slower

tox.ini

Lines changed: 128 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -1,122 +1,157 @@
11
[tox]
2+
skip_missing_interpreters = True
23
envlist =
3-
py{27,34,35,36,37,38,39}-default
4-
py{35,36,37,38,39}-aiohttp2
5-
py{35,36,37,38,39}-django22
6-
py{36,37,38,39}-django30
7-
py{36,37,38,39}-django31
8-
py{36,37,38,39}-django32
9-
py{27,36,37,38,39}-sqlalchemy
10-
py{34,35}-sqlalchemy
11-
coverage-report
4+
py{27,34,35,36,37,38,39}-core
125

13-
skip_missing_interpreters = True
6+
; Unavailable for python 2.7 & 3.4
7+
py{35,36,37,38,39}-ext-aiobotocore
8+
9+
; Unavailable for python 2.7 & 3.4
10+
py{35,36,37,38,39}-ext-aiohttp
11+
12+
py{27,34,35,36,37,38,39}-ext-botocore
13+
14+
py{27,34,35,36,37,38,39}-ext-bottle
15+
16+
; Django2 (2.2+) is only for python 3.5 +
17+
py{35,36,37,38,39}-ext-django-2
18+
19+
; Django3 is only for python 3.6+
20+
py{36,37,38,39}-ext-django-3
21+
22+
py{27,34,35,36,37,38,39}-ext-flask
23+
24+
py{27,34,35,36,37,38,39}-ext-flask_sqlalchemy
25+
26+
py{27,34,35,36,37,38,39}-ext-httplib
27+
28+
py{27,34,35,36,37,38,39}-ext-pg8000
29+
30+
py{27,34,35,36,37,38,39}-ext-psycopg2
31+
32+
py{27,34,35,36,37,38,39}-ext-pymysql
33+
34+
py{27,34,35,36,37,38,39}-ext-pynamodb
35+
36+
py{27,34,35,36,37,38,39}-ext-requests
37+
38+
py{27,34,35,36,37,38,39}-ext-sqlalchemy
39+
40+
py{27,34,35,36,37,38,39}-ext-sqlalchemy_core
41+
42+
py{27,34,35,36,37,38,39}-ext-sqlite3
1443

1544
[testenv]
16-
passenv = TOXENV CI TRAVIS TRAVIS_* CODECOV_*
45+
passenv = TOXENV CI CODECOV_*
46+
1747
deps =
48+
; Testing packages
1849
pytest > 3.0.0
1950
pytest-benchmark
20-
coverage==4.5.4
51+
coverage == 4.5.4
2152
codecov
22-
requests
23-
bottle >= 0.10
24-
flask >= 0.10
25-
sqlalchemy
26-
Flask-SQLAlchemy
53+
54+
; Packages common to all test environments
2755
future
28-
django22: Django==2.2.*
29-
django30: Django==3.0.*
30-
django31: Django==3.1.*
31-
django32: Django==3.2.*
32-
django{22,30,31,32}: django-fake-model
33-
pynamodb >= 3.3.1
34-
psycopg2
35-
pg8000
36-
testing.postgresql
37-
testing.mysqld
38-
webtest
39-
# Python2 only deps
40-
py{27}: enum34 mock
41-
42-
# pymysql deps
43-
py{27,34,35}: pymysql < 1.0.0
44-
py{36,37,38,39}: pymysql >= 1.0.0
45-
46-
# Python3.4 only deps
56+
wrapt
57+
58+
; Python 2.7 only deps
59+
py{27}: enum34
60+
py{27}: mock
61+
62+
; Python 3.4 only deps
4763
py34: typing >= 3.7.4.3
4864

49-
# Python3.5+ only deps
50-
py{35,36,37,38,39}: aiohttp >= 3.0.0
65+
; Python 3.5+ only deps
66+
; for some reason pytest-aiohttp is required for "core" tests
67+
; TODO: find and replace by more direct dependency
5168
py{35,36,37,38,39}: pytest-aiohttp
52-
py{35,36,37,38,39}: aiobotocore >= 0.10.0
5369

54-
commands =
55-
coverage erase
56-
py{27,34}-default: coverage run --append --source aws_xray_sdk -m py.test tests --ignore tests/ext/aiohttp --ignore tests/ext/aiobotocore --ignore tests/ext/django --ignore tests/test_async_local_storage.py --ignore tests/test_async_recorder.py --ignore tests/ext/sqlalchemy_core
57-
py{35,36,37,38,39}-default: coverage run --append --source aws_xray_sdk -m py.test tests --ignore tests/ext/django --ignore tests/ext/sqlalchemy_core
58-
py{27,36,37,38,39}-default: coverage run --append --source aws_xray_sdk -m py.test tests/ext/sqlalchemy_core
59-
py{34,35}-default: coverage run --append --source aws_xray_sdk -m py.test tests/ext/sqlalchemy_core/ --ignore tests/ext/sqlalchemy_core/test_sqlalchemy_core_2.py
60-
django{22,30,31,32}: coverage run --append --source aws_xray_sdk -m py.test tests/ext/django
61-
codecov
70+
ext-aiobotocore: aiobotocore >= 0.10.0
71+
ext-aiobotocore: pytest-aiohttp
72+
73+
ext-aiohttp: aiohttp >= 3.0.0
74+
; Breaking change where the `test_client` fixture was renamed.
75+
; Also, the stable version is only supported for Python 3.7+
76+
ext-aiohttp: pytest-aiohttp < 1.0.0
77+
78+
ext-requests: requests
79+
80+
ext-bottle: bottle >= 0.10
81+
ext-bottle: webtest
82+
83+
ext-flask: flask >= 0.10
84+
85+
ext-flask_sqlalchemy: flask >= 0.10
86+
ext-flask_sqlalchemy: Flask-SQLAlchemy
87+
88+
ext-sqlalchemy: sqlalchemy
89+
90+
ext-sqlalchemy_core: sqlalchemy
91+
ext-sqlalchemy_core: testing.postgresql
92+
ext-sqlalchemy_core: psycopg2
93+
94+
ext-django-2: Django >=2.0,<3.0
95+
ext-django-3: Django >=3.0,<4.0
96+
ext-django: django-fake-model
97+
98+
ext-pynamodb: pynamodb >= 3.3.1
99+
100+
ext-psycopg2: psycopg2
101+
ext-psycopg2: testing.postgresql
102+
103+
ext-pg8000: pg8000 <= 1.20.0
104+
ext-pg8000: testing.postgresql
105+
106+
ext-pymysql: testing.mysqld
107+
py{27,34,35}-ext-pymysql: pymysql < 1.0.0
108+
py{36,37,38,39}-ext-pymysql: pymysql >= 1.0.0
62109

63110
setenv =
64111
DJANGO_SETTINGS_MODULE = tests.ext.django.app.settings
65112
AWS_SECRET_ACCESS_KEY = fake_key
66113
AWS_ACCESS_KEY_ID=fake_id
67114

68-
[testenv:py35-aiohttp2]
69-
deps =
70-
pytest > 3.0.0
71-
aiohttp >= 2.3.0,<3.0.0
72-
pytest-aiohttp
73-
botocore
74-
coverage==4.5.4
75-
76115
commands =
77-
py{35}: coverage run --source aws_xray_sdk -m py.test tests/ext/aiohttp --ignore tests/ext/aiohttp/test_client.py
116+
coverage erase
78117

79-
[testenv:py36-aiohttp2]
80-
deps =
81-
pytest > 3.0.0
82-
aiohttp >= 2.3.0,<3.0.0
83-
pytest-aiohttp
84-
botocore
85-
coverage==4.5.4
118+
; Async methods are only available for python 3.5+
119+
py{27,34}-core: coverage run --append --source aws_xray_sdk -m pytest --ignore tests/ext --ignore tests/test_async_local_storage.py --ignore tests/test_async_recorder.py
120+
py{35,36,37,38,39}-core: coverage run --append --source aws_xray_sdk -m pytest --ignore tests/ext
86121

87-
commands =
88-
py{36}: coverage run --source aws_xray_sdk -m py.test tests/ext/aiohttp --ignore tests/ext/aiohttp/test_client.py
122+
ext-aiobotocore: coverage run --append --source aws_xray_sdk -m pytest tests/ext/aiobotocore
89123

90-
[testenv:py37-aiohttp2]
91-
deps =
92-
pytest > 3.0.0
93-
aiohttp >= 2.3.0,<3.0.0
94-
pytest-aiohttp
95-
botocore
96-
coverage==4.5.4
124+
ext-aiohttp: coverage run --append --source aws_xray_sdk -m pytest tests/ext/aiohttp
97125

98-
commands =
99-
py{37}: coverage run --source aws_xray_sdk -m py.test tests/ext/aiohttp --ignore tests/ext/aiohttp/test_client.py
126+
ext-botocore: coverage run --append --source aws_xray_sdk -m pytest tests/ext/botocore
100127

101-
[testenv:py38-aiohttp2]
102-
deps =
103-
pytest > 5.2.0
104-
aiohttp >= 3.6
105-
pytest-aiohttp
106-
botocore
107-
coverage==4.5.4
128+
ext-bottle: coverage run --append --source aws_xray_sdk -m pytest tests/ext/bottle
108129

109-
commands =
110-
py{38}: coverage run --source aws_xray_sdk -m py.test tests/ext/aiohttp --ignore tests/ext/aiohttp/test_client.py
130+
ext-django: coverage run --append --source aws_xray_sdk -m pytest tests/ext/django
111131

112-
[testenv:coverage-report]
113-
deps = coverage
114-
skip_install = true
115-
commands =
116-
# might need to add coverage combine at some point
117-
py{38}: coverage report
118-
py{38}: coverage html
132+
ext-flask: coverage run --append --source aws_xray_sdk -m pytest tests/ext/flask
133+
134+
ext-flask_sqlalchemy: coverage run --append --source aws_xray_sdk -m pytest tests/ext/flask_sqlalchemy
135+
136+
ext-httplib: coverage run --append --source aws_xray_sdk -m pytest tests/ext/httplib
137+
138+
ext-pg8000: coverage run --append --source aws_xray_sdk -m pytest tests/ext/pg8000
139+
140+
ext-psycopg2: coverage run --append --source aws_xray_sdk -m pytest tests/ext/psycopg2
141+
142+
ext-pymysql: coverage run --append --source aws_xray_sdk -m pytest tests/ext/pymysql
143+
144+
ext-pynamodb: coverage run --append --source aws_xray_sdk -m pytest tests/ext/pynamodb
145+
146+
ext-requests: coverage run --append --source aws_xray_sdk -m pytest tests/ext/requests
147+
148+
ext-sqlalchemy: coverage run --append --source aws_xray_sdk -m pytest tests/ext/sqlalchemy
149+
150+
; sqlalchemy_core - 2.0 style execution is not supported for python 3.4 & 3.5
151+
py{27,36,37,38,39}-ext-sqlalchemy_core: coverage run --append --source aws_xray_sdk -m pytest tests/ext/sqlalchemy_core
152+
py{34,35}-ext-sqlalchemy_core: coverage run --append --source aws_xray_sdk -m pytest tests/ext/sqlalchemy_core --ignore tests/ext/sqlalchemy_core/test_sqlalchemy_core_2.py
153+
154+
ext-sqlite3: coverage run --append --source aws_xray_sdk -m pytest tests/ext/sqlite3
119155

120-
[flake8]
121-
max-line-length=120
122-
exclude=tests
156+
; TODO: add additional logic to combine coverage from "core" and "ext" test runs
157+
; codecov

0 commit comments

Comments
 (0)