Skip to content

Conversation

@jscheffl
Copy link
Contributor

Another small increment to remove global statements for PR #58116

This just removes some global statements in unit tests, replaces with functools.cache()

global is evil.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR removes global statements from listener unit test modules, replacing them with a cleaner pattern using functools.cache() and dataclasses. The changes improve code maintainability by eliminating global state in favor of a cached singleton pattern.

  • Introduced ListenerState dataclass to encapsulate listener state
  • Replaced global variables with a cached get_listener_state() function
  • Updated test files to access listener state through the new getter function

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
airflow-core/tests/unit/listeners/full_listener.py Refactored from global variables to dataclass-based state with @cache decorator for singleton pattern
airflow-core/tests/unit/listeners/lifecycle_listener.py Refactored from global variables to dataclass-based state with @cache decorator for singleton pattern
airflow-core/tests/unit/listeners/test_listeners.py Updated assertions to access listener state via get_listener_state() method
airflow-core/tests/unit/jobs/test_base_job.py Updated assertions to access listener state via get_listener_state() method

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

jscheffl and others added 2 commits November 29, 2025 12:24
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@shahar1 shahar1 merged commit 8e18380 into apache:main Nov 29, 2025
63 checks passed
RoyLee1224 pushed a commit to RoyLee1224/airflow that referenced this pull request Dec 3, 2025
* Remove global from listener unit tests

* Fix dataclass

* Copilot review feedback

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Copilot review feedback

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copilot AI pushed a commit to jason810496/airflow that referenced this pull request Dec 5, 2025
* Remove global from listener unit tests

* Fix dataclass

* Copilot review feedback

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Copilot review feedback

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
itayweb pushed a commit to itayweb/airflow that referenced this pull request Dec 6, 2025
* Remove global from listener unit tests

* Fix dataclass

* Copilot review feedback

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Copilot review feedback

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants