diff --git a/.github/workflows/_release.yml b/.github/workflows/_release.yml index ee02baa..75f44be 100644 --- a/.github/workflows/_release.yml +++ b/.github/workflows/_release.yml @@ -165,9 +165,14 @@ jobs: run: make tests working-directory: ${{ inputs.working-directory }} + - name: Start local Atlas + run: bash scripts/start_local_atlas.sh + + - name: Get MongoDB URI + run: cat .local_atlas_uri >> $GITHUB_ENV + - name: Run integration tests env: - MONGODB_URI: ${{ secrets.MONGODB_ATLAS_URI }} OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} run: make integration_tests working-directory: ${{ inputs.working-directory }} diff --git a/.github/workflows/_test.yml b/.github/workflows/_test.yml index 89f8422..68bbee0 100644 --- a/.github/workflows/_test.yml +++ b/.github/workflows/_test.yml @@ -47,17 +47,18 @@ jobs: run: | make test + - name: Start local Atlas + working-directory: . + run: bash scripts/start_local_atlas.sh + + - name: Get MongoDB URI + working-directory: . + run: cat .local_atlas_uri >> $GITHUB_ENV + - name: Run integration tests env: - MONGODB_URI: ${{ secrets.MONGODB_ATLAS_URI }} OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} - run: | - if [[ "${{ github.event_name }}" == "push" ]]; then - # Only run on the min python version. - if [[ "${{ matrix.python-version }}" == "3.9" ]]; then - make integration_tests - fi - fi + run: make integration_tests working-directory: ${{ inputs.working-directory }} - name: Ensure the tests did not create any additional files diff --git a/.gitignore b/.gitignore index 45d553b..de92250 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ __pycache__ .mypy_cache_test .env .venv* +.local_atlas_uri diff --git a/libs/mongodb/tests/integration_tests/test_chain_example.py b/libs/mongodb/tests/integration_tests/test_chain_example.py index a67147b..1e61698 100644 --- a/libs/mongodb/tests/integration_tests/test_chain_example.py +++ b/libs/mongodb/tests/integration_tests/test_chain_example.py @@ -51,7 +51,7 @@ def collection() -> Collection: @pytest.mark.skipif( - "OPENAI_API_KEY" not in os.environ, reason="Requires OpenAI for chat responses." + os.environ.get("OPENAI_API_KEY") is not None, reason="Requires OpenAI for chat responses." ) def test_chain( collection: Collection, diff --git a/libs/mongodb/tests/integration_tests/test_retrievers.py b/libs/mongodb/tests/integration_tests/test_retrievers.py index db299cc..9c64e64 100644 --- a/libs/mongodb/tests/integration_tests/test_retrievers.py +++ b/libs/mongodb/tests/integration_tests/test_retrievers.py @@ -55,7 +55,7 @@ def embedding_openai() -> Embeddings: model="text-embedding-3-small", ) except Exception: - pytest.fail("test_retrievers expects OPENAI_API_KEY in os.environ") + pytest.skip("test_retrievers expects OPENAI_API_KEY in os.environ") @pytest.fixture(scope="module") diff --git a/scripts/start_local_atlas.sh b/scripts/start_local_atlas.sh new file mode 100644 index 0000000..883e971 --- /dev/null +++ b/scripts/start_local_atlas.sh @@ -0,0 +1,23 @@ +#!/bin/bash +set -eu + +echo "Starting the container" + +IMAGE=mongodb/mongodb-atlas-local:latest +podman pull $IMAGE + +CONTAINER_ID=$(podman run --rm -d -e DO_NOT_TRACK=1 --name mongodb_atlas_local -P $IMAGE) + +function wait() { + CONTAINER_ID=$1 + echo "waiting for container to become healthy..." + podman logs mongodb_atlas_local +} + +wait "$CONTAINER_ID" + +EXPOSED_PORT=$(podman inspect --format='{{ (index (index .NetworkSettings.Ports "27017/tcp") 0).HostPort }}' "$CONTAINER_ID") +export CONN_STRING="mongodb://127.0.0.1:$EXPOSED_PORT/?directConnection=true" +SCRIPT_DIR=$(realpath "$(dirname ${BASH_SOURCE[0]})") +ROOT_DIR=$(dirname $SCRIPT_DIR) +echo "MONGODB_URI=mongodb://127.0.0.1:$EXPOSED_PORT/?directConnection=true" > $ROOT_DIR/.local_atlas_uri