From 041d4f8ed2724f3f01921d8f78af191124035d98 Mon Sep 17 00:00:00 2001 From: Jens Troeger Date: Fri, 3 Oct 2025 11:51:07 +1000 Subject: [PATCH] test(pytest): remove unused variables and clean other minor lint to please ruff --- test/io/postgrest.py | 8 ++++---- test/io/test_io.py | 23 +++++++++-------------- test/io/test_sanity.py | 2 +- 3 files changed, 14 insertions(+), 19 deletions(-) diff --git a/test/io/postgrest.py b/test/io/postgrest.py index dd1af32ba..531a05bee 100644 --- a/test/io/postgrest.py +++ b/test/io/postgrest.py @@ -63,9 +63,9 @@ class PostgrestProcess: output = [] for _ in range(10): self.process.stdout.flush() - l = self.process.stdout.readline() - if l: - output.append(l.decode()) + line = self.process.stdout.readline() + if line: + output.append(line.decode()) if len(output) >= nlines: break time.sleep(0.1) @@ -152,7 +152,7 @@ def run( process.terminate() try: process.wait(timeout=1) - except: + except subprocess.TimeoutExpired: process.kill() process.wait() diff --git a/test/io/test_io.py b/test/io/test_io.py index 4c4afe4db..e1275cbd2 100644 --- a/test/io/test_io.py +++ b/test/io/test_io.py @@ -79,9 +79,8 @@ def test_jwt_errors(defaultenv): env = {**defaultenv, "PGRST_JWT_SECRET": SECRET, "PGRST_JWT_AUD": "io tests"} - relativeSeconds = lambda sec: int( - (datetime.now(timezone.utc) + timedelta(seconds=sec)).timestamp() - ) + def relativeSeconds(sec): + return int((datetime.now(timezone.utc) + timedelta(seconds=sec)).timestamp()) with run(env=env) as postgrest: headers = jwtauthheader({}, "other secret") @@ -328,7 +327,7 @@ def test_flush_pool_no_interrupt(defaultenv): def test_random_port_bound(defaultenv): "PostgREST should bind to a random port when PGRST_SERVER_PORT is 0." - with run(env=defaultenv, port="0") as postgrest: + with run(env=defaultenv, port="0"): assert True # liveness check is done by run(), so we just need to check that it doesn't fail @@ -1394,9 +1393,6 @@ def test_get_pgrst_version_with_keyval_connection_string(defaultenv): def test_log_postgrest_version(defaultenv): "Should show the PostgREST version in the logs" - - env = {**defaultenv, "PGRST_LOG_LEVEL": "crit"} - with run(env=defaultenv, no_startup_stdout=False) as postgrest: version = postgrest.session.head("/").headers["Server"].split("/")[1] @@ -1815,14 +1811,13 @@ def test_jwt_cache_purges_expired_entries(defaultenv): # The verification of actual cache size reduction is done manually, see https://github.com/PostgREST/postgrest/pull/3801#issuecomment-2620776041 # This test is written for code coverage of purgeExpired function - relativeSeconds = lambda sec: int( - (datetime.now(timezone.utc) + timedelta(seconds=sec)).timestamp() - ) + def relativeSeconds(sec): + return int((datetime.now(timezone.utc) + timedelta(seconds=sec)).timestamp()) - headers = lambda sec: jwtauthheader( - {"role": "postgrest_test_author", "exp": relativeSeconds(sec)}, - SECRET, - ) + def headers(sec): + return jwtauthheader( + {"role": "postgrest_test_author", "exp": relativeSeconds(sec)}, SECRET + ) env = { **defaultenv, diff --git a/test/io/test_sanity.py b/test/io/test_sanity.py index fe3213587..be90057ea 100644 --- a/test/io/test_sanity.py +++ b/test/io/test_sanity.py @@ -21,5 +21,5 @@ def test_plain_get(defaultenv): def test_no_pool_connection_available(defaultenv): "no_pool_connection_available option is functional" with run(env=defaultenv, no_pool_connection_available=True) as postgrest: - with pytest.raises(Exception) as e: + with pytest.raises(Exception): postgrest.session.get("/projects", timeout=1)