Skip to content

Commit

Permalink
fix(ci): unpin pytest, stop testing eventlet (getsentry#965)
Browse files Browse the repository at this point in the history
* fix(ci): Unpin pytest, stop testing eventlet

* eventlet is broken all the time in newer Python versions
* Channels 3.0 needs some adjustments.
* unpin pytest to satisfy conflicts between Python 3.9 and Python 2.7 environments

* install pytest-django for old django too

* downgrade pytest for old flask

* fix flask 1.11 error

* revert flask-dev hack, new pip resolver has landed

* fix django

* fix trytond

* drop trytond on py3.4

* remove broken assertion

* fix remaining issues

* fix: Formatting

* fix linters

* fix channels condition

* remove py3.6-flask-dev because its failing

Co-authored-by: sentry-bot <markus+ghbot@sentry.io>
  • Loading branch information
untitaker and sentry-bot authored Jan 7, 2021
1 parent c359291 commit 38b983e
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 67 deletions.
8 changes: 5 additions & 3 deletions sentry_sdk/integrations/flask.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
from sentry_sdk.integrations.wsgi import _ScopedResponse
from typing import Any
from typing import Dict
from werkzeug.datastructures import ImmutableTypeConversionDict
from werkzeug.datastructures import ImmutableMultiDict
from werkzeug.datastructures import FileStorage
from typing import Union
Expand Down Expand Up @@ -127,8 +126,11 @@ def env(self):
return self.request.environ

def cookies(self):
# type: () -> ImmutableTypeConversionDict[Any, Any]
return self.request.cookies
# type: () -> Dict[Any, Any]
return {
k: v[0] if isinstance(v, list) and len(v) == 1 else v
for k, v in self.request.cookies.items()
}

def raw_data(self):
# type: () -> bytes
Expand Down
5 changes: 2 additions & 3 deletions test-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
pytest==3.7.3
pytest
pytest-forked==1.1.3
tox==3.7.0
Werkzeug==0.15.5
Werkzeug
pytest-localserver==0.5.0
pytest-cov==2.8.1
jsonschema==3.2.0
pyrsistent==0.16.0 # TODO(py3): 0.17.0 requires python3, see https://github.com/tobgu/pyrsistent/issues/205
mock # for testing under python < 3.3

gevent
eventlet

newrelic
executing
Expand Down
16 changes: 14 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,15 @@
import pytest
import jsonschema

import gevent
import eventlet
try:
import gevent
except ImportError:
gevent = None

try:
import eventlet
except ImportError:
eventlet = None

import sentry_sdk
from sentry_sdk._compat import reraise, string_types, iteritems
Expand Down Expand Up @@ -284,6 +291,9 @@ def read_flush(self):
)
def maybe_monkeypatched_threading(request):
if request.param == "eventlet":
if eventlet is None:
pytest.skip("no eventlet installed")

try:
eventlet.monkey_patch()
except AttributeError as e:
Expand All @@ -293,6 +303,8 @@ def maybe_monkeypatched_threading(request):
else:
raise
elif request.param == "gevent":
if gevent is None:
pytest.skip("no gevent installed")
try:
gevent.monkey.patch_all()
except Exception as e:
Expand Down
9 changes: 8 additions & 1 deletion tests/integrations/django/myapp/routing.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import channels

from channels.http import AsgiHandler
from channels.routing import ProtocolTypeRouter

application = ProtocolTypeRouter({"http": AsgiHandler})
if channels.__version__ < "3.0.0":
channels_handler = AsgiHandler
else:
channels_handler = AsgiHandler()

application = ProtocolTypeRouter({"http": channels_handler})
1 change: 0 additions & 1 deletion tests/utils/test_general.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ def test_filename():
assert x("bogus", "bogus") == "bogus"

assert x("os", os.__file__) == "os.py"
assert x("pytest", pytest.__file__) == "pytest.py"

import sentry_sdk.utils

Expand Down
74 changes: 17 additions & 57 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ envlist =
{pypy,py2.7,py3.4,py3.5,py3.6,py3.7,py3.8,py3.9}-flask-{0.10,0.11,0.12,1.0}
{pypy,py2.7,py3.5,py3.6,py3.7,py3.8,py3.9}-flask-1.1

# TODO: see note in [testenv:flask-dev] below
; {py3.6,py3.7,py3.8,py3.9}-flask-dev
{py3.7,py3.8,py3.9}-flask-dev

{pypy,py2.7,py3.5,py3.6,py3.7,py3.8,py3.9}-bottle-0.12

Expand Down Expand Up @@ -64,8 +63,7 @@ envlist =

{py3.7,py3.8,py3.9}-tornado-{5,6}

{py3.4,py3.5,py3.6,py3.7,py3.8,py3.9}-trytond-{4.6,4.8,5.0}
{py3.5,py3.6,py3.7,py3.8,py3.9}-trytond-{5.2}
{py3.5,py3.6,py3.7,py3.8,py3.9}-trytond-{4.6,5.0,5.2}
{py3.6,py3.7,py3.8,py3.9}-trytond-{5.4}

{py2.7,py3.8,py3.9}-requests
Expand Down Expand Up @@ -94,25 +92,13 @@ deps =

django-{1.11,2.0,2.1,2.2,3.0,3.1,dev}: djangorestframework>=3.0.0,<4.0.0

; TODO: right now channels 3 is crashing tests/integrations/django/asgi/test_asgi.py
; see https://github.com/django/channels/issues/1549
{py3.7,py3.8,py3.9}-django-{1.11,2.0,2.1,2.2,3.0,3.1,dev}: channels>2,<3
{py3.7,py3.8,py3.9}-django-{1.11,2.0,2.1,2.2,3.0,3.1,dev}: pytest-asyncio==0.10.0
{py3.7,py3.8,py3.9}-django-{1.11,2.0,2.1,2.2,3.0,3.1,dev}: channels>2
{py3.7,py3.8,py3.9}-django-{1.11,2.0,2.1,2.2,3.0,3.1,dev}: pytest-asyncio
{py2.7,py3.7,py3.8,py3.9}-django-{1.11,2.2,3.0,3.1,dev}: psycopg2-binary

django-{1.6,1.7,1.8}: pytest-django<3.0

; TODO: once we upgrade pytest to at least 5.4, we can split it like this:
; django-{1.9,1.10,1.11,2.0,2.1}: pytest-django<4.0
; django-{2.2,3.0,3.1}: pytest-django>=4.0

; (note that py3.9, on which we recently began testing, only got official
; support in pytest-django >=4.0, so we probablly want to upgrade the whole
; kit and kaboodle at some point soon)

; see https://pytest-django.readthedocs.io/en/latest/changelog.html#v4-0-0-2020-10-16
django-{1.9,1.10,1.11,2.0,2.1,2.2,3.0,3.1}: pytest-django<4.0

django-{1.6,1.7}: pytest-django<3.0
django-{1.8,1.9,1.10,1.11,2.0,2.1}: pytest-django<4.0
django-{2.2,3.0,3.1}: pytest-django>=4.0
django-dev: git+https://github.com/pytest-dev/pytest-django#egg=pytest-django

django-1.6: Django>=1.6,<1.7
Expand All @@ -135,9 +121,8 @@ deps =
flask-1.0: Flask>=1.0,<1.1
flask-1.1: Flask>=1.1,<1.2

# TODO: see note in [testenv:flask-dev] below
; flask-dev: git+https://github.com/pallets/flask.git#egg=flask
; flask-dev: git+https://github.com/pallets/werkzeug.git#egg=werkzeug
flask-dev: git+https://github.com/pallets/flask.git#egg=flask
flask-dev: git+https://github.com/pallets/werkzeug.git#egg=werkzeug

bottle-0.12: bottle>=0.12,<0.13
bottle-dev: git+https://github.com/bottlepy/bottle#egg=bottle
Expand Down Expand Up @@ -207,9 +192,10 @@ deps =
trytond-5.4: trytond>=5.4,<5.5
trytond-5.2: trytond>=5.2,<5.3
trytond-5.0: trytond>=5.0,<5.1
trytond-4.8: trytond>=4.8,<4.9
trytond-4.6: trytond>=4.6,<4.7

trytond-4.8: werkzeug<1.0

redis: fakeredis

rediscluster-1: redis-py-cluster>=1.0.0,<2.0.0
Expand Down Expand Up @@ -302,41 +288,15 @@ basepython =
pypy: pypy

commands =
py.test {env:TESTPATH} {posargs}
django-{1.6,1.7}: pip install pytest<4

; https://github.com/pytest-dev/pytest/issues/5532
{py3.5,py3.6,py3.7,py3.8,py3.9}-flask-{0.10,0.11,0.12}: pip install pytest<5

# TODO: This is broken out as a separate env so as to be able to override the
# werkzeug version. (You can't do it just by letting one version be specifed in
# a requirements file and specifying a different version in one testenv, see
# https://github.com/tox-dev/tox/issues/1390.) The issue is that as of 11/11/20,
# flask-dev has made a change which werkzeug then had to compensate for in
# https://github.com/pallets/werkzeug/pull/1960. Since we've got werkzeug
# pinned at 0.15.5 in test-requirements.txt, we don't get this fix.
; trytond tries to import werkzeug.contrib
trytond-5.0: pip install werkzeug<1.0

# At some point, we probably want to revisit this, since the list copied from
# test-requirements.txt could easily get stale.
[testenv:flask-dev]
deps =
git+https://github.com/pallets/flask.git#egg=flask
git+https://github.com/pallets/werkzeug.git#egg=werkzeug

# everything below this point is from test-requirements.txt (minus, of
# course, werkzeug)
pytest==3.7.3
pytest-forked==1.1.3
tox==3.7.0
pytest-localserver==0.5.0
pytest-cov==2.8.1
jsonschema==3.2.0
pyrsistent==0.16.0 # TODO(py3): 0.17.0 requires python3, see https://github.com/tobgu/pyrsistent/issues/205
mock # for testing under python < 3.3

gevent
eventlet

newrelic
executing
asttokens
py.test {env:TESTPATH} {posargs}

[testenv:linters]
commands =
Expand Down

0 comments on commit 38b983e

Please sign in to comment.