Fix pytest-asyncio configuration and treq_asgi hex escapes

- Add asyncio_mode = "auto" to pytest configuration for async tests
- Update treq_asgi.py badrequest class to support hex escapes
This commit is contained in:
Benoit Chesneau 2026-03-26 17:59:40 +01:00
parent da8bd4850a
commit d40a374547
2 changed files with 9 additions and 6 deletions

View File

@ -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

View File

@ -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