Skip to content

Commit

Permalink
Fix tests in starlette v0.23.1 (#752)
Browse files Browse the repository at this point in the history
* Fix tests in starlette v0.23.1

* Fix conditional tests

* Add comment to bg_task test
  • Loading branch information
lrafeei committed Jan 31, 2023
1 parent 1d8d078 commit 5844bb1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
9 changes: 6 additions & 3 deletions tests/framework_starlette/test_bg_tasks.py
Expand Up @@ -87,10 +87,12 @@ def _test():
response = app.get("/" + route)
assert response.status == 200

BUG_COMPLETELY_FIXED = (starlette_version >= (0, 21, 0)) or (
starlette_version >= (0, 20, 1) and sys.version_info[:2] > (3, 7)
# The bug was fixed in version 0.21.0 but re-occured in 0.23.1.
# The bug was also not present on 0.20.1 to 0.23.1 if using Python3.7.
BUG_COMPLETELY_FIXED = (0, 21, 0) <= starlette_version < (0, 23, 1) or (
(0, 20, 1) <= starlette_version < (0, 23, 1) and sys.version_info[:2] > (3, 7)
)
BUG_PARTIALLY_FIXED = (0, 20, 1) <= starlette_version < (0, 21, 0) and sys.version_info[:2] <= (3, 7)
BUG_PARTIALLY_FIXED = (0, 20, 1) <= starlette_version < (0, 21, 0) or starlette_version >= (0, 23, 1)

if BUG_COMPLETELY_FIXED:
# Assert both web transaction and background task transactions are present.
Expand All @@ -103,6 +105,7 @@ def _test():
# The background task no longer blocks the completion of the web request/web transaction.
# However, the BaseHTTPMiddleware causes the task to be cancelled when the web request disconnects, so there are no
# longer function traces or background task transactions.
# In version 0.23.1, the check to see if more_body exists is removed, reverting behavior to this model
_test = validate_transaction_metrics("_test_bg_tasks:run_%s_bg_task" % route, scoped_metrics=[route_metric])(
_test
)
Expand Down
3 changes: 1 addition & 2 deletions tox.ini
Expand Up @@ -357,8 +357,7 @@ deps =
framework_starlette-starlette0015: starlette<0.16
framework_starlette-starlette0019: starlette<0.20
framework_starlette-starlette002001: starlette==0.20.1
; Starlette latest version temporarily pinned
framework_starlette-starlettelatest: starlette<0.23.1
framework_starlette-starlettelatest: starlette
framework_strawberry: starlette
framework_strawberry-strawberrylatest: strawberry-graphql
framework_tornado: pycurl
Expand Down

0 comments on commit 5844bb1

Please sign in to comment.