Skip to content

Commit

Permalink
[asgi] add test for #1883
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasleveil committed Jul 21, 2023
1 parent 7603a1f commit 6ae8d62
Showing 1 changed file with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

# pylint: disable=too-many-lines

import asyncio
import sys
import unittest
from timeit import default_timer
Expand Down Expand Up @@ -796,5 +797,38 @@ async def wrapped_app(scope, receive, send):
)


class TestAsgiApplicationRaisingError(AsgiTestBase):
def tearDown(self):
pass

@mock.patch(
"opentelemetry.instrumentation.asgi.collect_custom_request_headers_attributes",
side_effect=ValueError("whatever"),
)
def test_asgi_issue_1883(
self, mock_collect_custom_request_headers_attributes
):
"""
Test that exception UnboundLocalError local variable 'start' referenced before assignment is not raises
See https:/open-telemetry/opentelemetry-python-contrib/issues/1883
"""
app = otel_asgi.OpenTelemetryMiddleware(simple_asgi)
self.seed_app(app)
self.send_default_request()
try:
asyncio.get_event_loop().run_until_complete(
self.communicator.stop()
)
except ValueError as exc_info:
self.assertEqual(exc_info.args[0], "whatever")
except Exception as exc_info: # pylint: disable=W0703
self.fail(
"expecting ValueError('whatever'), received instead: "
+ str(exc_info)
)
else:
self.fail("expecting ValueError('whatever')")


if __name__ == "__main__":
unittest.main()

0 comments on commit 6ae8d62

Please sign in to comment.