diff --git a/tests/test_asgi.py b/tests/test_asgi.py index 78e24193..aa2cf1cf 100644 --- a/tests/test_asgi.py +++ b/tests/test_asgi.py @@ -48,9 +48,14 @@ def tearDown(self): asyncio.get_event_loop().run_until_complete( self.communicator.wait() ) - + + async def create_communicator(self, app): + return ApplicationCommunicator(app, self.scope) + def seed_app(self, app): - self.communicator = ApplicationCommunicator(app, self.scope) + self.communicator = asyncio.get_event_loop().run_until_complete( + self.create_communicator(app) + ) def send_input(self, payload): asyncio.get_event_loop().run_until_complete( @@ -148,9 +153,9 @@ def test_gzip(self): increments = 2 self.increment_metrics(metric_name, help_text, increments) app = make_asgi_app(self.registry) - self.seed_app(app) # Send input with gzip header. self.scope["headers"] = [(b"accept-encoding", b"gzip")] + self.seed_app(app) self.send_input({"type": "http.request", "body": b""}) # Assert outputs are compressed. outputs = self.get_all_output() @@ -164,9 +169,9 @@ def test_gzip_disabled(self): self.increment_metrics(metric_name, help_text, increments) # Disable compression explicitly. app = make_asgi_app(self.registry, disable_compression=True) - self.seed_app(app) # Send input with gzip header. self.scope["headers"] = [(b"accept-encoding", b"gzip")] + self.seed_app(app) self.send_input({"type": "http.request", "body": b""}) # Assert outputs are not compressed. outputs = self.get_all_output() @@ -175,8 +180,8 @@ def test_gzip_disabled(self): def test_openmetrics_encoding(self): """Response content type is application/openmetrics-text when appropriate Accept header is in request""" app = make_asgi_app(self.registry) - self.seed_app(app) self.scope["headers"] = [(b"Accept", b"application/openmetrics-text")] + self.seed_app(app) self.send_input({"type": "http.request", "body": b""}) content_type = self.get_response_header_value('Content-Type').split(";")[0] diff --git a/tox.ini b/tox.ini index deb74e14..f6c4f9ac 100644 --- a/tox.ini +++ b/tox.ini @@ -1,15 +1,14 @@ [tox] -envlist = coverage-clean,py{3.9,3.10,3.11,3.12,3.13,py3.9,3.9-nooptionals},coverage-report,flake8,isort,mypy +envlist = coverage-clean,py{3.9.18,3.10,3.11,3.12,3.13,py3.9,3.9-nooptionals},coverage-report,flake8,isort,mypy [testenv] deps = coverage pytest attrs - {py3.9,pypy3.9}: twisted - # NOTE: Pinned due to https://github.com/prometheus/client_python/issues/1020 - py3.9: asgiref==3.7 - pypy3.9: asgiref==3.7 + {py3.9.18,pypy3.9}: twisted + py3.9.18: asgiref + pypy3.9: asgiref commands = coverage run --parallel -m pytest {posargs} [testenv:py3.9-nooptionals]