]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
Declare 'elapsed' value before usage in async connection tests
authorDenis Laxalde <denis.laxalde@dalibo.com>
Fri, 5 Nov 2021 12:21:23 +0000 (13:21 +0100)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Wed, 10 Nov 2021 01:57:39 +0000 (02:57 +0100)
Resolves mypy error:
  error: No binding for nonlocal "elapsed" found  [misc]

tests/test_connection_async.py

index 7f115ca34ad77efa9d726e0210590bdf44e94d28..67c297a19645f2b0ab2e79803133b1db98437354 100644 (file)
@@ -52,6 +52,8 @@ async def test_connect_timeout():
         await asyncio.sleep(1.5)
         s.close()
 
+    elapsed: float = 0
+
     async def connect():
         t0 = time.time()
         with pytest.raises(psycopg.OperationalError, match="timeout expired"):
@@ -61,7 +63,6 @@ async def test_connect_timeout():
         nonlocal elapsed
         elapsed = time.time() - t0
 
-    elapsed = 0
     await asyncio.gather(closer(), connect())
     assert elapsed == pytest.approx(1.0, abs=0.05)