Skip to content

Add missing tests for cncf.kubernetes script and delete utilities #72265

Closed

Description

@jroachgolf84

Description

Two modules in the cncf.kubernetes provider have no dedicated test module, and (unlike most entries on the OVERLOOKED_TESTS list) they are not covered indirectly. Nothing under any providers/*/tests/ directory imports them at all:

Module Expected test file
providers/cncf/kubernetes/src/airflow/providers/cncf/kubernetes/python_kubernetes_script.py providers/cncf/kubernetes/tests/unit/cncf/kubernetes/test_python_kubernetes_script.py
providers/cncf/kubernetes/src/airflow/providers/cncf/kubernetes/utils/delete_from.py providers/cncf/kubernetes/tests/unit/cncf/kubernetes/utils/test_delete_from.py

Both are currently suppressed in the OVERLOOKED_TESTS allowlist in airflow-core/tests/unit/always/test_project_structure.py.

This is a scoped subset of the meta issue #35442, limited to the cncf.kubernetes provider.

What should these tests cover?

python_kubernetes_script.py backs the @task.kubernetes decorator. remove_task_decorator does string surgery on user source, stripping @setup, @teardown and the task decorator itself, with _balance_parens walking nested parentheses to find where a parameterised decorator ends. That is easy to break and the failure mode is silently corrupted user code, so it is worth covering directly:

  • a decorator with no arguments, with arguments, and with nested parentheses inside the arguments
  • source carrying @setup and @teardown alongside the task decorator
  • source where the decorator name never appears, which should return the input unchanged
  • write_python_script rendering the Jinja template to the target file, including render_template_as_native_obj=True selecting NativeEnvironment, and StrictUndefined raising on a missing context variable

While writing these it is worth pinning the current behaviour of the inner _remove_task_decorator, which reads python_source from the enclosing scope rather than its own py_source argument. The two happen to be the same object on every iteration of the loop that calls it, so the result is correct today, but nothing stops that from silently changing.

delete_from.py is vendored from kubernetes_asyncio and mirrors the upstream create_from_yaml helpers. Worth covering:

  • the API class name derivation in _delete_from_yaml_single_item from apiVersion, covering the core group, a named group, .k8s.io stripping, and DNS subdomain to CamelCase conversion
  • the kind conversion from CamelCase to snake_case
  • namespaced versus non namespaced dispatch, meaning delete_namespaced_<kind> when the API exposes it and delete_<kind> otherwise
  • a namespace in the document metadata taking precedence over the namespace argument, which the code calls out explicitly
  • List kinds fanning out over items and inheriting apiVersion from the parent document
  • ApiExceptions being collected rather than raised eagerly, then surfaced together as FailToDeleteError, plus the FailToDeleteError.__str__ formatting

These can all be driven with mocked kubernetes.client API classes using autospec, so no cluster is required.

Definition of Done

  1. Add the two test modules at the paths in the table above.
  2. Remove the two corresponding entries from OVERLOOKED_TESTS in airflow-core/tests/unit/always/test_project_structure.py
  3. Both of these tests should pass:
breeze testing providers-tests providers/cncf/kubernetes/tests/unit/cncf/kubernetes/test_python_kubernetes_script.py

breeze testing providers-tests providers/cncf/kubernetes/tests/unit/cncf/kubernetes/utils/test_delete_from.py

Drafted-by: Claude Code (Opus 5); reviewed and edited by @jroachgolf84 before posting.

Activity

  1. jroachgolf84 commented on Aug 29, 2026

    @jroachgolf84
    CollaboratorAuthor

    This is an issue that is reserved for the Airflow Summit "Contributors" Workshop. This is denoted with the label contributors-workshop. Out of respect for the organizers and participants of this workshop, please do not implement a PR that addresses this issue.

    If this issue is still open following Airflow Summit, the label will be removed and the issue can be picked up.

  2. self-assigned this
    on Aug 29, 2026
  3. jroachgolf84 commented on Sep 2, 2026

    @jroachgolf84
    CollaboratorAuthor

    This issue is now open for contribution. Please feel free to create a PR!

  4. removed their assignment
    on Sep 2, 2026
  5. mohit716 commented on Sep 16, 2026

    @mohit716

    I'd love to take a stab at this issue and work on the missing test coverage!

  6. Sanskar121543 commented on Oct 14, 2026

    @Sanskar121543

    I'd like to work on this - will add the two missing test modules (test_python_kubernetes_script.py and test_delete_from.py) per the spec above.

  7. Sanskar121543 commented on Oct 14, 2026

    @Sanskar121543

    Correction: I missed that this already has open PRs (#74424, #74524, #72461) addressing it - apologies for the noise, stepping back from this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions