diff --git a/pyproject.toml b/pyproject.toml index e43639f2..8638c570 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -80,6 +80,8 @@ main = "gunicorn.app.pasterapp:serve" norecursedirs = ["examples", "lib", "local", "src", "tests/docker"] testpaths = ["tests/"] addopts = "--assert=plain --cov=gunicorn --cov-report=xml" +asyncio_mode = "auto" +asyncio_default_fixture_loop_scope = "function" filterwarnings = [ # Eventlet patches select module, which breaks asyncio event loop cleanup # This is expected behavior when testing eventlet worker diff --git a/tests/treq_asgi.py b/tests/treq_asgi.py index ab7c7655..adad3560 100644 --- a/tests/treq_asgi.py +++ b/tests/treq_asgi.py @@ -209,13 +209,14 @@ class badrequest: self.fname = fname self.name = os.path.basename(fname) - with open(self.fname) as handle: + with open(self.fname, 'rb') as handle: self.data = handle.read() - self.data = self.data.replace("\n", "").replace("\\r\\n", "\r\n") - self.data = self.data.replace("\\0", "\000").replace("\\n", "\n").replace("\\t", "\t") - if "\\" in self.data: - raise AssertionError("Unexpected backslash in test data") - self.data = self.data.encode('latin1') + self.data = self.data.replace(b"\n", b"").replace(b"\\r\\n", b"\r\n") + self.data = self.data.replace(b"\\0", b"\000").replace(b"\\n", b"\n").replace(b"\\t", b"\t") + # Handle hex escape sequences for binary data (e.g., \x0D for bare CR) + self.data = decode_hex_escapes(self.data) + if b"\\" in self.data: + raise AssertionError("Unexpected backslash in test data - only handling HTAB, NUL, CRLF, and hex escapes") def send_all(self): yield self.data