chore: skip integration tests when no target DB is configured#422
Closed
erichare wants to merge 1 commit into
Closed
chore: skip integration tests when no target DB is configured#422erichare wants to merge 1 commit into
erichare wants to merge 1 commit into
Conversation
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.
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Running any test in this repo currently requires a target Data API/DB to be configured. With no credentials set,
tests/conftest.pyimportstests/preprocess_env, which raisesValueError("No credentials.")at module-load time — aborting collection of the entire suite, including the unit tests: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 ofASTRA_DB_API_ENDPOINT/LOCAL_DATA_API_ENDPOINT/DOCKER_COMPOSE_LOCAL_DATA_APIis set, record this via a newTARGET_DB_EMPTYflag (with safe defaults forIS_ASTRA_DB,DOCKER_COMPOSE_LOCAL_DATA_API,SECONDARY_KEYSPACE) instead of raising. The token-provider setup is guarded accordingly.tests/conftest.py— add apytest_collection_modifyitemshook that, whenTARGET_DB_EMPTY, skips every test located under anintegration/directory or whose fixture closure needs a live database (data_api_credentials_kwargs& friends —data_api_credentials_kwargsis 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_EMPTYisFalseand the hook returns immediately — a complete no-op.unit.ymlis 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-only→ 730 collected, no crash (previously: hardValueError).pytest tests/base/unit→ 257 passed, 36 skipped, 0 DB errors. (One unrelated failure,test_dataapitimestamp_lifecycle, reproduces onmaintoo — it's a local-timezone artifact and passes in UTC CI.)pytest tests/base/integration→ 436 skipped, 0 errors.pytest tests/admin tests/vectorize→ 19 skipped, 0 errors.TARGET_DB_EMPTYisTruewith no creds,Falsewith Astra creds (hook no-ops in CI).ruff check tests,ruff format --check tests,mypy tests→ all clean.