Pushkal-Gupta opened a new pull request, #76189:
URL: https://github.com/apache/airflow/pull/76189

   Running a single API route test file, the way
   [AGENTS.md](https://github.com/apache/airflow/blob/main/AGENTS.md) documents 
it,
   goes wrong for two files in
   `airflow-core/tests/unit/api_fastapi/core_api/routes/public/`. Neither shows 
up
   in CI, because CI runs whole suites and both problems need the file to run on
   its own.
   
   ### test_version.py fails whenever it runs first
   
   ```
   pytest 
airflow-core/tests/unit/api_fastapi/core_api/routes/public/test_version.py
   packaging.version.InvalidVersion: Invalid version: 'MOCK_VERSION'
   ```
   
   The test patched `...routes.public.version.airflow.__version__`. The route 
does
   `import airflow` and reads the attribute, so that target is the attribute on 
the
   shared `airflow` module, not a name local to the route. Building the app then
   imports `airflow.providers.fab.www.app`, which imports
   `airflow.providers.fab.version_compat`, which runs `Version(__version__)` at
   import time and sees `MOCK_VERSION`.
   
   In a suite some earlier test has already imported that module, so the parse
   happened before the patch and the test passes. Run the file alone and it is 
the
   first thing to build the app, so the import lands inside the patch.
   
   The fix patches the module reference the route holds rather than the 
attribute on
   the shared module. The route only reads `__version__`, so a stand-in carrying
   that one attribute is enough, and nothing outside the route sees a changed
   version.
   
   ### test_connections.py writes a file into the working directory
   
   `test_existing_connection_lookup_preserves_team_scope` leaves a zero byte 
file
   behind, named after the fixture connection:
   
   ```
   $ cd /tmp/empty && pytest .../test_connections.py
   168 passed
   $ ls
   'some_login@some_host_a:8080'
   ```
   
   The stored connection supplies `login`, `host` and `port`, the request body
   supplies `conn_type: sqlite`, and the route merges the two and really 
connects,
   so the sqlite hook creates a database file named after the merged target in 
the
   process's working directory. Run from a clone, that is an untracked file in 
the
   repository root, and the colon in the name makes it awkward to remove on some
   platforms.
   
   The test now runs in `tmp_path`, so the file the hook insists on creating 
lands
   in pytest's own directory.
   
   ### Verification
   
   Both fixes were checked by reverting them and watching the symptom come back:
   `test_version.py` fails on its own before and passes after, and
   `test_connections.py` leaves the file before and leaves an empty directory
   after.
   
   The whole `routes/public/` suite is 2616 passed, 5 failed, both before and 
after
   these changes. The 5 are the same ones before and after and are unrelated to
   this PR: 4 in `test_plugins.py`, which counts plugins and is off by one when
   provider plugins fail to import locally, and 1 in `test_dag_parsing.py`. They
   fail on an unmodified checkout in any order.
   
   `ruff format --check` and `ruff check` pass on both files, as do all the prek
   hooks that apply to them. No newsfragment: this changes tests only.
   
   ---
   
   ##### Was generative AI tooling used to co-author this PR?
   
   - [X] Yes (please specify the tool below)
   
   Generated-by: Claude Code (Opus 5) following [the 
guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#gen-ai-assisted-contributions)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to