Skip to content

chore: skip integration tests when no target DB is configured#422

Closed
erichare wants to merge 1 commit into
mainfrom
chore-skip-integration-tests-no-db
Closed

chore: skip integration tests when no target DB is configured#422
erichare wants to merge 1 commit into
mainfrom
chore-skip-integration-tests-no-db

Conversation

@erichare

Copy link
Copy Markdown
Collaborator

Summary

Running any test in this repo currently requires a target Data API/DB to be configured. With no credentials set, tests/conftest.py imports tests/preprocess_env, which raises ValueError("No credentials.") at module-load time — aborting collection of the entire suite, including the unit tests:

ImportError while loading conftest 'tests/conftest.py'.
tests/preprocess_env.py:128: in <module>
    raise ValueError("No credentials.")
E   ValueError: No credentials.

This PR makes the integration tests skip (instead of crashing the run) when no target DB is configured, so contributors can run the unit suite with zero environment setup.

What changed

  • tests/preprocess_env.py — when none of ASTRA_DB_API_ENDPOINT / LOCAL_DATA_API_ENDPOINT / DOCKER_COMPOSE_LOCAL_DATA_API is set, record this via a new TARGET_DB_EMPTY flag (with safe defaults for IS_ASTRA_DB, DOCKER_COMPOSE_LOCAL_DATA_API, SECONDARY_KEYSPACE) instead of raising. The token-provider setup is guarded accordingly.
  • tests/conftest.py — add a pytest_collection_modifyitems hook that, when TARGET_DB_EMPTY, skips every test located under an integration/ directory or whose fixture closure needs a live database (data_api_credentials_kwargs & friends — data_api_credentials_kwargs is the only fixture that performs network calls during setup, and all integration tests depend on it transitively).
  • CHANGES, DEVELOPING.md — documentation.

Safety: no CI behavior change

When a target DB is configured (always the case in CI), TARGET_DB_EMPTY is False and the hook returns immediately — a complete no-op. unit.yml is intentionally left untouched (it still passes credentials), so the DB-dependent unit tests keep running there with full coverage.

Test plan

Verified locally with no DB env configured:

  • pytest tests/base --collect-only730 collected, no crash (previously: hard ValueError).
  • pytest tests/base/unit257 passed, 36 skipped, 0 DB errors. (One unrelated failure, test_dataapitimestamp_lifecycle, reproduces on main too — it's a local-timezone artifact and passes in UTC CI.)
  • pytest tests/base/integration436 skipped, 0 errors.
  • pytest tests/admin tests/vectorize19 skipped, 0 errors.
  • TARGET_DB_EMPTY is True with no creds, False with Astra creds (hook no-ops in CI).
  • ruff check tests, ruff format --check tests, mypy tests → all clean.

Previously, running any test (even the unit suite) without a target Data
API/DB configured aborted collection with `ValueError("No credentials.")`,
because tests/conftest.py imports tests/preprocess_env at module load.

Now, when none of ASTRA_DB_API_ENDPOINT / LOCAL_DATA_API_ENDPOINT /
DOCKER_COMPOSE_LOCAL_DATA_API is set, preprocess_env records this via a
TARGET_DB_EMPTY flag (with safe defaults) instead of raising. A
pytest_collection_modifyitems hook in tests/conftest.py then skips every
test that lives under an `integration` directory or whose fixture closure
needs a live database, so `pytest tests/base/unit` (and the whole suite)
runs credential-free instead of crashing.

When a target DB is configured (always the case in CI) TARGET_DB_EMPTY is
False and the hook is a no-op: the full suite runs exactly as before.
@erichare

Copy link
Copy Markdown
Collaborator Author

Superseded by #423. The requirement was clarified to the opposite direction: the integration tests should be skipped when the target database is non-empty (to avoid running the destructive suite against a populated database), not when no DB is configured.

@erichare erichare closed this Jun 17, 2026
@erichare erichare deleted the chore-skip-integration-tests-no-db branch June 17, 2026 16:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant