Repository navigation
Add an offline test target that no AWS account authorizes (GH-1495) #1532
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
3cc2a9d
389c205
d6c0518
3518bf7
ae20c6c
0abd0d0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -119,8 +119,8 @@ uv run --env-file .env just test sqla | |
| uv run --env-file .env just test sqla-async | ||
| ``` | ||
|
|
||
| Despite the recipe's "unit tests" label, `just test pyathena` includes AWS integration tests. | ||
| The recipes use eight pytest workers, so check your account's Athena concurrency quotas. | ||
| `just test pyathena` includes the AWS integration tests; `just test offline`, described below, runs only the tests that need no AWS. | ||
| The recipes that use AWS run eight pytest workers, so check your account's Athena concurrency quotas. | ||
| They also rerun a failed test once when its failure message is an Athena internal error or `Invalid S3 request`, and report the first attempt's traceback. | ||
| A failure of the session setup fails each test that uses AWS and is not tried again; a direct `pytest` invocation does not rerun. | ||
| Do not overlap test runs that share AWS resources or quota. | ||
|
|
@@ -134,33 +134,33 @@ A targeted run helps during development but does not replace other coverage requ | |
|
|
||
| (testing-offline)= | ||
|
|
||
| ### Run self-contained tests offline | ||
| ### Run the tests that need no AWS | ||
|
|
||
| The pandas and Polars result-set modules have self-contained tests that can run without AWS access. | ||
| Reuse the `.env` file described in the AWS environment section if it is already configured. | ||
| For an offline-only setup, create a gitignored `.env` file in the repository root with these placeholder values: | ||
| `just test offline` runs the tests under `tests/pyathena/` that carry no `aws` mark, without AWS credentials or a `.env` file: | ||
|
|
||
| ```ini | ||
| AWS_DEFAULT_REGION=us-east-1 | ||
| AWS_ATHENA_S3_STAGING_DIR=s3://pyathena-offline-placeholder/ | ||
| AWS_ATHENA_WORKGROUP=offline | ||
| AWS_ATHENA_SPARK_WORKGROUP=offline | ||
| AWS_EC2_METADATA_DISABLED=true | ||
| ```bash | ||
| just lint | ||
| just test offline | ||
| ``` | ||
|
|
||
| After `just lint`, load `.env` and run: | ||
| The recipe first syncs the environment as `uv run` does. | ||
| It then unsets every `AWS_*` and `FSSPEC_*` variable, including those of a loaded `.env` file, and `HTTP_PROXY`, `HTTPS_PROXY`, and `ALL_PROXY` in upper and lower case, sets `NO_PROXY` and `no_proxy` to `*`, keeps uv from loading a `.env` file, and sets: | ||
|
|
||
| - placeholder values for the four settings that `tests/__init__.py` requires; | ||
| - placeholder credentials that no AWS account accepts, empty AWS, boto, and fsspec configuration, and `AWS_EC2_METADATA_DISABLED=true`, so that no request made by accident is authorized; | ||
| - `AWS_ENDPOINT_URL=https://offline.invalid`, a reserved name that does not resolve, with `AWS_MAX_ATTEMPTS=1` and `POLARS_CLOUD_MAX_RETRIES=0`, so that a request that boto3 or Polars makes by accident fails at once without reaching AWS. | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Independent review (relayed): Codex CLI (
Validation at |
||
| The `S3FileSystem` that PyAthena creates for PyArrow does not read `AWS_ENDPOINT_URL`; its requests reach AWS and are rejected for the placeholder credentials. | ||
|
|
||
| The recipe also runs without the rerun plugin, whose reruns cover only service-side errors of Athena and S3. | ||
| A test that reaches AWS in `just test offline` gets a connection error or a rejected request; make it request `aws_test_schema`, as described above, which also gives it the `aws` mark. | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Self-review round 1 (behavior and implementation; base FINDINGS (repaired): the guide told a contributor to give a test that reaches AWS the Deferred: shortening the list of what the recipe sets ( |
||
|
|
||
| The offline target covers a change whose behavior these tests exercise without AWS, such as parameter formatting, SQL compilation, the conversion of result files, or filesystem logic checked with stubbed responses. | ||
| When a change affects a request to AWS, or how PyAthena reads what AWS returns, also run the affected `aws` tests against your AWS environment, for example: | ||
|
|
||
| ```bash | ||
| uv run --env-file .env pytest --noconftest -p no:rerunfailures -q \ | ||
| tests/pyathena/pandas/test_result_set.py \ | ||
| tests/pyathena/polars/test_result_set.py | ||
| uv run --env-file .env pytest -n 1 -m aws tests/pyathena/test_cursor.py | ||
| ``` | ||
|
|
||
| The four AWS configuration values are required by `tests/__init__.py`, which pytest still imports with `--noconftest`. | ||
| The offline-only `.env` example disables EC2 metadata to prevent implicit credential lookup through that service. | ||
| `--noconftest` excludes the conftest fixtures, including the AWS session setup; disabling the rerun plugin also avoids its local socket setup in restricted environments. | ||
| Use this invocation only for self-contained modules; integration tests need their normal fixtures and a real AWS environment. | ||
|
|
||
| ### S3 null-version moves | ||
|
|
||
| The null-version move regression tests create three dedicated temporary buckets: | ||
|
|
@@ -270,7 +270,8 @@ Retain dtype and schema checks, option contexts, and resource cleanup where appl | |
| ## GitHub Actions | ||
|
|
||
| The Test workflow runs for pull requests that change files other than `docs/` and Markdown. | ||
| It runs the offline checks (`just lint`) on each of them, including Drafts and external forks, and runs the AWS suites as follows: | ||
| It runs the offline checks (`just lint`, and `just test offline` on the newest supported Python version) on each of them, including Drafts and external forks. | ||
| The AWS suites start only after the offline checks pass, and run as follows: | ||
|
|
||
| | Trigger | PyAthena suite | SQLAlchemy tests | Spark tests | Python versions | | ||
| | --- | --- | --- | --- | --- | | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,21 +35,46 @@ lint: license-headers | |
| license-headers: | ||
| uv run python scripts/check_license_headers.py | ||
|
|
||
| # Run tests: just test (pyathena|sqla|sqla-async) | ||
| # Run tests: just test (pyathena|offline|sqla|sqla-async) | ||
| test target="help": | ||
| @just _test-{{ if target =~ "^-" { "help" } else { target } }} | ||
|
|
||
| _test-help: | ||
| @echo "Usage: just test <target>" | ||
| @echo "" | ||
| @echo "Targets:" | ||
| @echo " pyathena Run unit tests (runs lint first)" | ||
| @echo " pyathena Run the PyAthena tests, including AWS integration tests (runs lint first)" | ||
| @echo " offline Run the PyAthena tests that need no AWS, with no AWS credentials" | ||
| @echo " sqla Run SQLAlchemy dialect tests" | ||
| @echo " sqla-async Run SQLAlchemy async dialect tests" | ||
|
|
||
| _test-pyathena: lint | ||
| uv run pytest -n 8 {{PYTEST_RERUN}} --cov pyathena --cov-report html --cov-report term tests/pyathena/ | ||
|
|
||
| # Sync the environment first, as uv run does, with the developer's settings. | ||
| # Then unset every AWS and fsspec setting and HTTP_PROXY, HTTPS_PROXY, and | ||
| # ALL_PROXY in either case, set NO_PROXY and no_proxy to '*', and give the four | ||
| # settings that tests/__init__.py requires placeholder values. A request | ||
| # made by accident carries credentials that no account accepts, and the clients | ||
| # that read AWS_ENDPOINT_URL send it to a reserved name that does not resolve | ||
| # (RFC 6761), with AWS_MAX_ATTEMPTS=1 and POLARS_CLOUD_MAX_RETRIES=0. uv must not | ||
| # load a .env file back. | ||
| _test-offline: | ||
| #!/usr/bin/env bash | ||
| set -euo pipefail | ||
| uv run --no-env-file true | ||
| for name in $(compgen -e AWS_) $(compgen -e FSSPEC_); do unset "$name"; done | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Independent review (relayed): Codex CLI (
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Repair self-review, round 1 perspective (
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Repair self-review, round 2 perspective (
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Independent follow-up (relayed): Codex CLI (
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Repair self-review, both perspectives (
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Independent follow-up 2 (relayed): Codex CLI (
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Repair self-review, both perspectives (
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Independent follow-up 3 (relayed): Codex CLI (session
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Independent follow-up 4 (relayed): Codex CLI (session |
||
| unset HTTP_PROXY HTTPS_PROXY ALL_PROXY http_proxy https_proxy all_proxy | ||
| export NO_PROXY='*' no_proxy='*' | ||
| export AWS_DEFAULT_REGION=us-west-2 | ||
| export AWS_ATHENA_S3_STAGING_DIR=s3://pyathena-offline-placeholder/ | ||
| export AWS_ATHENA_WORKGROUP=offline AWS_ATHENA_SPARK_WORKGROUP=offline | ||
| export AWS_ACCESS_KEY_ID=offline AWS_SECRET_ACCESS_KEY=offline | ||
| export AWS_CONFIG_FILE=/dev/null AWS_SHARED_CREDENTIALS_FILE=/dev/null BOTO_CONFIG=/dev/null | ||
| export AWS_EC2_METADATA_DISABLED=true FSSPEC_CONFIG_DIR=/dev/null | ||
| export AWS_ENDPOINT_URL=https://offline.invalid AWS_MAX_ATTEMPTS=1 POLARS_CLOUD_MAX_RETRIES=0 | ||
| uv run --no-sync --no-env-file pytest -n auto -p no:rerunfailures -m "not aws" tests/pyathena/ | ||
|
|
||
| _test-sqla: | ||
| uv run pytest -n 8 {{PYTEST_RERUN}} --cov pyathena --cov-report html --cov-report term tests/sqlalchemy/ | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Self-review round 1 (behavior and implementation; base
6acb688be38db78ffe6c6fe094281549e2c2cbf3, reviewed3cc2a9db974e890c02969e36a6c30b63076fd640, repaired at389c205bf26cc4e09c3755fc1f7a62ee264460bd). Covered: the_test-offlinerecipe and help, theofflinejob and thechangesgate, the docs and agent guidance. Inputs: my own pass,/code-review high,/simplify.FINDINGS (repaired): the AWS suites waited for
offlinebut not forlint(/simplifyaltitude and efficiency);changesnow needs both, at no cost, sincelintfinishes first. The job had no timeout although the AWS suites wait for it (/code-review);timeout-minutes: 20. CI on this Draft at3cc2a9db: theofflinejob passed, 3941 tests in 48.7 s on 4 workers, 68 s in all.Deferred with reasons: running the offline job on every supported Python version, or merging it into
linton 3.12 (#1495 specifies the newest version); the hard-coded3.15besidePYTHON_VERSIONS(expressions cannot take the last element of that JSON list; a comment ties them); the duplicated setup-uv/setup-python steps (the same astest-suite.yaml);-m awsin the AWS suite to skip the offline tests there (it would drop offline coverage on the other Python versions of the Release run); the 1-3 minutes the gate adds before the AWS suites (accepted to avoid AWS runs for changes that fail offline).