You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "kyungjunleeme (via GitHub)" <gi...@apache.org> on 2025/07/02 05:33:12 UTC

[I] Standardize test usage of context: Context across operator tests (avoid context=None) [airflow]

kyungjunleeme opened a new issue, #52679:
URL: https://github.com/apache/airflow/issues/52679

   ### Description
   
   ### šŸ“Œ Title
   
   Standardize test usage of `context: Context` across operator tests (avoid `context=None`)
   
   ---
   
   ### šŸ“ Description
   
   Many operator tests across the Airflow codebase currently invoke `execute()` like this:
   
   ```python
   operator.execute(None)
   ```
   
   However, the `execute()` method is explicitly typed as:
   
   ```python
   def execute(self, context: Context) -> None:
   ```
   
   To align with this contract and improve typing correctness and future maintainability, we should replace `None` with a minimal `Context` object (e.g., `{}` or `MagicMock(spec=Context)`).
   
   #### āœ… Benefits of this change:
   - Aligns test cases with actual method signature (`context: Context`)
   - Avoids potential mypy/type-checking issues (especially in Airflow 3+)
   - Prevents misleading behavior in tests by not passing `None` when `context` is required
   - Improves clarity and correctness in test expectations
   
   ---
   
   ### šŸ”„ Suggested Migration Pattern
   
   **Before:**
   ```python
   operator.execute(None)
   ```
   
   **After:**
   ```python
   
   if TYPE_CHECKING:
       try:
           from airflow.sdk.definitions.context import Context
       except ImportError:
           # TODO: Remove once provider drops support for Airflow 2
           from airflow.utils.context import Context
   
   mock_context: Context = {}
   operator.execute(mock_context)
   ```
   
   **Or (stricter typing):**
   ```python
   from unittest.mock import MagicMock
   
   if TYPE_CHECKING:
       try:
           from airflow.sdk.definitions.context import Context
       except ImportError:
           # TODO: Remove once provider drops support for Airflow 2
           from airflow.utils.context import Context
   
   mock_context = MagicMock(spec=Context)
   operator.execute(mock_context)
   ```
   
   
   
   ### Use case/motivation
   
   _No response_
   
   ### Related issues
   
   _No response_
   
   ### Are you willing to submit a PR?
   
   - [x] Yes I am willing to submit a PR!
   
   ### Code of Conduct
   
   - [x] I agree to follow this project's [Code of Conduct](https://github.com/apache/airflow/blob/main/CODE_OF_CONDUCT.md)
   


-- 
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: commits-unsubscribe@airflow.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Standardize test usage of context: Context across operator tests (avoid context=None) [airflow]

Posted by "potiuk (via GitHub)" <gi...@apache.org>.
potiuk commented on issue #52679:
URL: https://github.com/apache/airflow/issues/52679#issuecomment-3986450434

   @kyungjunleeme We are unassigning you from this issue as part of our updated [assignment policy](https://github.com/apache/airflow/blob/main/contributing-docs/04_how_to_contribute.rst#contribute-code-changes).
   
   This is not meant to discourage your contribution — quite the opposite! You are still very welcome to work on this issue and submit a PR for it. Simply comment that you are working on it and open a PR when ready.
   
   We found that formal assignments were not working well, as they often prevented others from contributing when the assignee was not actively working on the issue.


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Standardize test usage of context: Context across operator tests (avoid context=None) [airflow]

Posted by "kyungjunleeme (via GitHub)" <gi...@apache.org>.
kyungjunleeme commented on issue #52679:
URL: https://github.com/apache/airflow/issues/52679#issuecomment-3988103028

   Yes, I understood


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Standardize test usage of context: Context across operator tests (avoid context=None) [airflow]

Posted by "kyungjunleeme (via GitHub)" <gi...@apache.org>.
kyungjunleeme commented on issue #52679:
URL: https://github.com/apache/airflow/issues/52679#issuecomment-3026514104

   I’d be happy to take ownership of this issue and address it project-wide. Please feel free to assign me to the issue.


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Standardize test usage of context: Context across operator tests (avoid context=None) [airflow]

Posted by "potiuk (via GitHub)" <gi...@apache.org>.
potiuk commented on issue #52679:
URL: https://github.com/apache/airflow/issues/52679#issuecomment-3028512004

   nice!
   


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Standardize test usage of context: Context across operator tests (avoid context=None) [airflow]

Posted by "kyungjunleeme (via GitHub)" <gi...@apache.org>.
kyungjunleeme commented on issue #52679:
URL: https://github.com/apache/airflow/issues/52679#issuecomment-3029414602

   Thank you


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org