From c77a1235f4d4f4d88129c13fa9586840ede48ce4 Mon Sep 17 00:00:00 2001 From: Anton Pirker Date: Wed, 7 Feb 2024 15:44:49 +0100 Subject: [PATCH] Minor improvements (#2714) - better name for Pyramid event processor - better test data and output for AWS Lambda tests - one better asset in threading test - minor tox cleanup to make gevent more prominent --- sentry_sdk/integrations/pyramid.py | 4 +- tests/integrations/aws_lambda/client.py | 12 +++-- tests/integrations/aws_lambda/test_aws.py | 20 ++++---- .../integrations/threading/test_threading.py | 3 +- tox.ini | 49 ++++++++++--------- 5 files changed, 48 insertions(+), 40 deletions(-) diff --git a/sentry_sdk/integrations/pyramid.py b/sentry_sdk/integrations/pyramid.py index 6bfed0318f..80750f0268 100644 --- a/sentry_sdk/integrations/pyramid.py +++ b/sentry_sdk/integrations/pyramid.py @@ -215,7 +215,7 @@ def size_of_file(self, postdata): def _make_event_processor(weak_request, integration): # type: (Callable[[], Request], PyramidIntegration) -> EventProcessor - def event_processor(event, hint): + def pyramid_event_processor(event, hint): # type: (Dict[str, Any], Dict[str, Any]) -> Dict[str, Any] request = weak_request() if request is None: @@ -231,4 +231,4 @@ def event_processor(event, hint): return event - return event_processor + return pyramid_event_processor diff --git a/tests/integrations/aws_lambda/client.py b/tests/integrations/aws_lambda/client.py index 298ebd920d..265ce6a520 100644 --- a/tests/integrations/aws_lambda/client.py +++ b/tests/integrations/aws_lambda/client.py @@ -240,7 +240,7 @@ def run_lambda_function( FunctionName=full_fn_name, ) print( - "Lambda function in AWS already existing, taking it (and do not create a local one)" + f"Lambda function {full_fn_name} in AWS already existing, taking it (and do not create a local one)" ) except client.exceptions.ResourceNotFoundException: function_exists_in_aws = False @@ -251,9 +251,14 @@ def run_lambda_function( dir_already_existing = os.path.isdir(base_dir) if dir_already_existing: - print("Local Lambda function directory already exists, skipping creation") + print( + f"Local Lambda function directory ({base_dir}) already exists, skipping creation" + ) if not dir_already_existing: + print( + f"Creating Lambda function package ({full_fn_name}) locally in directory {base_dir}" + ) os.mkdir(base_dir) _create_lambda_package( base_dir, code, initial_handler, layer, syntax_check, subprocess_kwargs @@ -316,9 +321,10 @@ def clean_up(): waiter = client.get_waiter("function_active_v2") waiter.wait(FunctionName=full_fn_name) + print(f"Created Lambda function in AWS: {full_fn_name}") except client.exceptions.ResourceConflictException: print( - "Lambda function already exists, this is fine, we will just invoke it." + f"Lambda function ({full_fn_name}) already existing in AWS, this is fine, we will just invoke it." ) response = client.invoke( diff --git a/tests/integrations/aws_lambda/test_aws.py b/tests/integrations/aws_lambda/test_aws.py index 7141e2a7cb..54dde0798d 100644 --- a/tests/integrations/aws_lambda/test_aws.py +++ b/tests/integrations/aws_lambda/test_aws.py @@ -462,23 +462,23 @@ def test_handler(event, context): [ { "headers": { - "Host": "x.io", - "X-Forwarded-Proto": "http" + "Host": "x1.io", + "X-Forwarded-Proto": "https" }, "httpMethod": "GET", - "path": "/somepath", + "path": "/path1", "queryStringParameters": { - "done": "true" + "done": "false" }, "dog": "Maisey" }, { "headers": { - "Host": "x.io", + "Host": "x2.io", "X-Forwarded-Proto": "http" }, - "httpMethod": "GET", - "path": "/somepath", + "httpMethod": "POST", + "path": "/path2", "queryStringParameters": { "done": "true" }, @@ -539,11 +539,11 @@ def test_handler(event, context): if has_request_data: request_data = { - "headers": {"Host": "x.io", "X-Forwarded-Proto": "http"}, + "headers": {"Host": "x1.io", "X-Forwarded-Proto": "https"}, "method": "GET", - "url": "http://x.io/somepath", + "url": "https://x1.io/path1", "query_string": { - "done": "true", + "done": "false", }, } else: diff --git a/tests/integrations/threading/test_threading.py b/tests/integrations/threading/test_threading.py index 555694133e..97f480f155 100644 --- a/tests/integrations/threading/test_threading.py +++ b/tests/integrations/threading/test_threading.py @@ -131,7 +131,8 @@ def run(self): t.join() del t - assert not gc.collect() + unreachable_objects = gc.collect() + assert unreachable_objects == 0 @pytest.mark.forked diff --git a/tox.ini b/tox.ini index deccf9adb0..90806b4220 100644 --- a/tox.ini +++ b/tox.ini @@ -8,6 +8,9 @@ envlist = # === Common === {py2.7,py3.5,py3.6,py3.7,py3.8,py3.9,py3.10,py3.11,py3.12}-common + # === Gevent === + {py2.7,py3.6,py3.8,py3.10,py3.11}-gevent + # === Integrations === # General format is {pythonversion}-{integrationname}-v{frameworkversion} # 1 blank line between different integrations @@ -112,9 +115,6 @@ envlist = {py3.10,py3.11,py3.12}-flask-v{3} {py3.10,py3.11,py3.12}-flask-latest - # Gevent - {py2.7,py3.6,py3.8,py3.10,py3.11}-gevent - # GCP {py3.7}-gcp @@ -235,18 +235,32 @@ deps = # with the -r flag -r test-requirements.txt - py3.8-common: hypothesis - linters: -r linter-requirements.txt linters: werkzeug<2.3.0 - # Common + # === Common === + py3.8-common: hypothesis {py3.6,py3.7,py3.8,py3.9,py3.10,py3.11,py3.12}-common: pytest-asyncio<=0.21.1 # See https://github.com/pytest-dev/pytest/issues/9621 # and https://github.com/pytest-dev/pytest-forked/issues/67 # for justification of the upper bound on pytest {py3.6,py3.7,py3.8,py3.9,py3.10,py3.11,py3.12}-common: pytest<7.0.0 + # === Gevent === + # See http://www.gevent.org/install.html#older-versions-of-python + # for justification of the versions pinned below + py3.5-gevent: gevent==20.9.0 + # See https://stackoverflow.com/questions/51496550/runtime-warning-greenlet-greenlet-size-changed + # for justification why greenlet is pinned here + py3.5-gevent: greenlet==0.4.17 + {py2.7,py3.6,py3.7,py3.8,py3.9,py3.10,py3.11,py3.12}-gevent: gevent>=22.10.0, <22.11.0 + # See https://github.com/pytest-dev/pytest/issues/9621 + # and https://github.com/pytest-dev/pytest-forked/issues/67 + # for justification of the upper bound on pytest + {py3.6,py3.7,py3.8,py3.9,py3.10,py3.11,py3.12}-gevent: pytest<7.0.0 + + # === Integrations === + # AIOHTTP aiohttp-v3.4: aiohttp~=3.4.0 aiohttp-v3.8: aiohttp~=3.8.0 @@ -360,7 +374,8 @@ deps = # FastAPI fastapi: httpx - fastapi: anyio<4.0.0 # thats a dep of httpx + # (this is a dependency of httpx) + fastapi: anyio<4.0.0 fastapi: pytest-asyncio<=0.21.1 fastapi: python-multipart fastapi: requests @@ -379,19 +394,6 @@ deps = flask-v3: Flask~=3.0 flask-latest: Flask - # Gevent - # See http://www.gevent.org/install.html#older-versions-of-python - # for justification of the versions pinned below - py3.5-gevent: gevent==20.9.0 - # See https://stackoverflow.com/questions/51496550/runtime-warning-greenlet-greenlet-size-changed - # for justification why greenlet is pinned here - py3.5-gevent: greenlet==0.4.17 - {py2.7,py3.6,py3.7,py3.8,py3.9,py3.10,py3.11,py3.12}-gevent: gevent>=22.10.0, <22.11.0 - # See https://github.com/pytest-dev/pytest/issues/9621 - # and https://github.com/pytest-dev/pytest-forked/issues/67 - # for justification of the upper bound on pytest - {py3.6,py3.7,py3.8,py3.9,py3.10,py3.11,py3.12}-gevent: pytest<7.0.0 - # GQL gql-v{3.4}: gql[all]~=3.4.0 gql-latest: gql[all] @@ -525,7 +527,8 @@ deps = starlette: python-multipart starlette: requests starlette: httpx - starlette: anyio<4.0.0 # thats a dep of httpx + # (this is a dependency of httpx) + starlette: anyio<4.0.0 starlette: jinja2 starlette-v0.19: starlette~=0.19.0 starlette-v0.20: starlette~=0.20.0 @@ -540,7 +543,6 @@ deps = starlite: requests starlite: cryptography starlite: pydantic<2.0.0 - {py3.8,py3.9}-starlite: typing-extensions==4.5.0 # this is used by pydantic, which is used by starlite. When the problem is fixed in here or pydantic, this can be removed starlite-v{1.48}: starlite~=1.48.0 starlite-v{1.51}: starlite~=1.51.0 @@ -576,6 +578,7 @@ deps = setenv = PYTHONDONTWRITEBYTECODE=1 common: TESTPATH=tests + gevent: TESTPATH=tests aiohttp: TESTPATH=tests/integrations/aiohttp ariadne: TESTPATH=tests/integrations/ariadne arq: TESTPATH=tests/integrations/arq @@ -593,8 +596,6 @@ setenv = falcon: TESTPATH=tests/integrations/falcon fastapi: TESTPATH=tests/integrations/fastapi flask: TESTPATH=tests/integrations/flask - # run all tests with gevent - gevent: TESTPATH=tests gcp: TESTPATH=tests/integrations/gcp gql: TESTPATH=tests/integrations/gql graphene: TESTPATH=tests/integrations/graphene