Skip to content

Commit

Permalink
Fix starlette tests for new release (#256)
Browse files Browse the repository at this point in the history
* Fix starlette tests for new release

* Fix python version specific failures
  • Loading branch information
TimPansino authored Jun 23, 2021
1 parent 208344e commit d40ff60
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 11 deletions.
37 changes: 28 additions & 9 deletions tests/framework_starlette/test_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import sys

import pytest
import starlette

from newrelic.common.object_names import callable_name
from testing_support.fixtures import (
override_ignore_status_codes,
validate_transaction_errors,
Expand Down Expand Up @@ -88,17 +92,32 @@ def _test():


@pytest.mark.parametrize("app_name", ("no_error_handler",))
@validate_transaction_metrics(
"_test_application:middleware_factory.<locals>.middleware",
scoped_metrics=[
("Function/_test_application:middleware_factory.<locals>.middleware", 1)
],
rollup_metrics=[FRAMEWORK_METRIC],
)
def test_exception_in_middleware(target_application, app_name):
app = target_application[app_name]
with pytest.raises(ValueError):
app.get("/crash_me_now")

from starlette import __version__ as version
starlette_version = tuple(int(v) for v in version.split("."))

# Starlette >=0.15 raises an exception group instead of reraising the ValueError
# This only occurs on Python versions >=3.8
if sys.version_info[0:2] > (3, 7) and starlette_version >= (0, 15, 0):
from anyio._backends._asyncio import ExceptionGroup
exc_type = ExceptionGroup
else:
exc_type = ValueError

@validate_transaction_metrics(
"_test_application:middleware_factory.<locals>.middleware",
scoped_metrics=[
("Function/_test_application:middleware_factory.<locals>.middleware", 1)
],
rollup_metrics=[FRAMEWORK_METRIC],
)
@validate_transaction_errors(errors=[callable_name(exc_type)])
def _test():
with pytest.raises(exc_type): # Later versions of starlette
app.get("/crash_me_now")
_test()


@pytest.mark.parametrize(
Expand Down
5 changes: 3 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ envlist =
python-framework_pyramid-{pypy3,py36,py37,py38,py39}-Pyramidmaster,
python-framework_sanic-{py38,pypy3}-sanic{190301,1906,1812,1912,200904,210300}
python-framework_sanic-{py36,py37,py38,pypy3}-saniclatest
python-framework_starlette-{py36,py37,py38,py39,pypy3},
python-framework_starlette-{py36,py37,py38,py39,pypy3}-starlette{0014,latest},
libcurl-framework_tornado-{py36,py37,py38,py39,pypy3}-tornado0600,
libcurl-framework_tornado-{py36,py37,py38,py39,pypy3}-tornadomaster,
rabbitmq-messagebroker_pika-{py27,py36,py37,py38,py39,pypy,pypy3}-pika{0.13,latest},
Expand Down Expand Up @@ -254,7 +254,8 @@ deps =
framework_sanic-sanic210300: sanic<21.3.1
framework_sanic-saniclatest: sanic
framework_sanic-sanic{1812,190301,1906}: aiohttp
framework_starlette: starlette
framework_starlette-starlette0014: starlette<0.15
framework_starlette-starlettelatest: starlette
framework_tornado: pycurl
framework_tornado-tornado0600: tornado<6.1
framework_tornado-tornadomaster: https://github.com/tornadoweb/tornado/archive/master.zip
Expand Down

0 comments on commit d40ff60

Please sign in to comment.