Skip to content

Commit 9e04f44

Browse files
test: address PR review feedback on rig + connector test guards
- in_scope defaults False on CriticalPathStatus so a future evaluate() regression that forgets it under-gates (warning) rather than over-gates (spurious build block). [greptile] - widen connector integration skip guards (redshift, snowflake, gdrive, minio, pcs) to require every env var the test hard-references, so a partially configured env skips cleanly instead of failing. [coderabbit] - usage_v2 test_helper: swap Usage via an autouse monkeypatch fixture instead of a module-level rebind that leaks FakeUsage into later tests. - build_index_payload test: evict the helper module from sys.modules after binding it, so later importers in the same process get a real copy. - drop dead tox `runner` alias (its unit-runner group was removed). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01C5HQX5CSoMR6RzHtXcfwJt
1 parent aa11380 commit 9e04f44

9 files changed

Lines changed: 30 additions & 15 deletions

File tree

backend/prompt_studio/prompt_studio_core_v2/tests/test_build_index_payload.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,12 @@ def _restore_modules() -> None:
9494
else:
9595
sys.modules[name] = original
9696
_SAVED_MODULES.clear()
97+
# The helper imported above is now cached bound to the stubbed globals.
98+
# Evict it so any later importer in this process gets a real copy; our
99+
# own `_psh_mod`/`PromptStudioHelper` refs are already bound, unaffected.
100+
sys.modules.pop(
101+
"prompt_studio.prompt_studio_core_v2.prompt_studio_helper", None
102+
)
97103

98104

99105
try:

backend/usage_v2/tests/test_helper.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from typing import Any
1818
from unittest.mock import MagicMock
1919

20+
import pytest
2021
import usage_v2.helper as helper_mod
2122
from usage_v2.helper import UsageHelper
2223

@@ -26,8 +27,12 @@ class FakeUsage:
2627
objects = MagicMock(name="Usage.objects")
2728

2829

29-
# Swap the symbol get_usage_by_model resolves; leaves the real model untouched.
30-
helper_mod.Usage = FakeUsage
30+
@pytest.fixture(autouse=True)
31+
def _swap_usage(monkeypatch: pytest.MonkeyPatch) -> None:
32+
# Swap the symbol get_usage_by_model resolves, per-test, so monkeypatch
33+
# restores the real model afterwards — a module-level rebind would leak
34+
# FakeUsage into every later test in the same process.
35+
monkeypatch.setattr(helper_mod, "Usage", FakeUsage)
3136

3237

3338
# ---------------------------------------------------------------------------

tests/rig/critical_paths.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,10 @@ class CriticalPathStatus:
6767
notes: str = ""
6868
# True when a declared covering group belongs to the tier(s) this run
6969
# covered. An out-of-scope gap (coverage only in an unrun tier, or none
70-
# declared) must not gate under --fail-on-critical-gap.
71-
in_scope: bool = True
70+
# declared) must not gate under --fail-on-critical-gap. Defaults False so a
71+
# regression that forgets to pass it can only under-gate (spurious warning),
72+
# never over-gate (spurious build block).
73+
in_scope: bool = False
7274

7375
def __post_init__(self) -> None:
7476
# Make the contradictory states unrepresentable rather than relying on

tox.ini

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,5 @@ commands = python -m tests.rig {posargs:list-groups}
6969
# These mirror the pre-rig envs so existing scripts / CI snippets keep working
7070
# during the migration. They delegate to the corresponding rig group.
7171

72-
[testenv:runner]
73-
commands = python -m tests.rig run unit-runner {posargs}
74-
7572
[testenv:sdk1]
7673
commands = python -m tests.rig run unit-sdk1 {posargs}

unstract/connectors/tests/databases/test_redshift_db.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
class TestRedshift(unittest.TestCase):
88
@unittest.skipUnless(
9-
os.environ.get("REDSHIFT_TEST_PASSWORD"),
9+
os.environ.get("REDSHIFT_TEST_PASSWORD") and os.environ.get("REDSHIFT_TEST_HOST"),
1010
"Integration test requires a live Redshift cluster and REDSHIFT_TEST_* env vars",
1111
)
1212
def test_user_name_and_password(self):

unstract/connectors/tests/databases/test_snowflake_db.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66

77
class TestSnowflakeDB(unittest.TestCase):
88
@unittest.skipUnless(
9-
os.environ.get("SNOWFLAKE_TEST_PASSWORD"),
9+
os.environ.get("SNOWFLAKE_TEST_PASSWORD")
10+
and os.environ.get("SNOWFLAKE_TEST_USER")
11+
and os.environ.get("SNOWFLAKE_TEST_ACCOUNT"),
1012
"Integration test requires a live Snowflake account and SNOWFLAKE_TEST_* env vars",
1113
)
1214
def test_something(self):

unstract/connectors/tests/filesystems/test_google_drive_fs.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66

77
class TestGoogleDriveFS(unittest.TestCase):
88
@unittest.skipUnless(
9-
os.environ.get("GDRIVE_GOOGLE_SERVICE_ACCOUNT"),
10-
"Integration test requires GDRIVE_GOOGLE_SERVICE_ACCOUNT",
9+
os.environ.get("GDRIVE_GOOGLE_SERVICE_ACCOUNT")
10+
and os.environ.get("GDRIVE_GOOGLE_PROJECT_ID"),
11+
"Integration test requires GDRIVE_GOOGLE_SERVICE_ACCOUNT and GDRIVE_GOOGLE_PROJECT_ID",
1112
)
1213
def test_basic(self):
1314
self.assertEqual(GoogleDriveFS.requires_oauth(), True)

unstract/connectors/tests/filesystems/test_miniofs.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,9 @@ def test_s3(self) -> None:
3333
print(s3.get_fsspec_fs().ls("unstract-user-storage"))
3434

3535
@unittest.skipUnless(
36-
os.environ.get("MINIO_ACCESS_KEY_ID"),
37-
"Integration test requires a live MinIO and MINIO_ACCESS_KEY_ID",
36+
os.environ.get("MINIO_ACCESS_KEY_ID")
37+
and os.environ.get("MINIO_SECRET_ACCESS_KEY"),
38+
"Integration test requires a live MinIO and MINIO_ACCESS_KEY_ID + MINIO_SECRET_ACCESS_KEY",
3839
)
3940
def test_minio(self) -> None:
4041
self.assertEqual(MinioFS.requires_oauth(), False)

unstract/connectors/tests/filesystems/test_pcs.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66

77
class TestPCS_FS(unittest.TestCase):
88
@unittest.skipUnless(
9-
os.environ.get("GOOGLE_STORAGE_ACCESS_KEY_ID"),
10-
"Integration test requires GOOGLE_STORAGE_ACCESS_KEY_ID",
9+
os.environ.get("GOOGLE_STORAGE_ACCESS_KEY_ID")
10+
and os.environ.get("GOOGLE_STORAGE_SECRET_ACCESS_KEY"),
11+
"Integration test requires GOOGLE_STORAGE_ACCESS_KEY_ID and GOOGLE_STORAGE_SECRET_ACCESS_KEY",
1112
)
1213
def test_pcs(self) -> None:
1314
self.assertEqual(UnstractCloudStorage.requires_oauth(), False)

0 commit comments

Comments
 (0)