-
Notifications
You must be signed in to change notification settings - Fork 14.5k
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
Refactor ti clear next method kwargs tests #19194
Refactor ti clear next method kwargs tests #19194
Conversation
It's probably better to refactor using def _failure():
raise AirflowException
def _skip():
raise AirflowSkipException
# Others...
@pytest.mark.parametrize(
"state, func",
[
(State.FAILED, _failure),
(State.SKIPPED, _skip),
# Others...
],
)
def test_task_wipes_next_fields(self, session, dag_maker, state, func):
with dag_maker("test_deferred_method_clear"):
task = PythonOperator(
...,
python_callable=func,
)
... |
Thanks @uranusjr. We are utilizing |
@ReadytoRocc, I think @uranusjr's suggestion is even better fwiw. |
Thanks @jedcunningham and @uranusjr. Refactored as suggested. |
The PR most likely needs to run full matrix of tests because it modifies parts of the core of Airflow. However, committers might decide to merge it quickly and take the risk. If they don't merge it quickly - please rebase it to the latest main at your convenience, or amend the last commit of the PR, and push it with --force-with-lease. |
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed in 5 days if no further activity occurs. Thank you for your contributions. |
@ReadytoRocc, geez sorry, didn't realize this never got merged! Can you rebase on main when you get the chance? |
9768d0d
to
05d0adc
Compare
Thanks. @jedcunningham and @uranusjr I needed to slightly modify some of the code due to a mypy check that was not present when this PR was originally opened. Please review again before merging. Thanks! |
tests/models/test_taskinstance.py
Outdated
retries=_retries, | ||
retry_delay=_retry_delay, | ||
python_callable=_raise_af_exception, | ||
op_args=[exception_type], |
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.
if you remove exception_type
as a param in _raise_af_exception
you can also remove op_kwargs
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.
Thanks @dstandish, will do.
tests/models/test_taskinstance.py
Outdated
""" | ||
Test that ensures that tasks wipe their next_method and next_kwargs | ||
when they go into a state of FAILED, SKIPPED, SUCCESS, UP_FOR_RESCHEDULE, or UP_FOR_RETRY. | ||
Test that ensures that tasks wipe their next_method and next_kwargs for the configured states: |
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.
Test that ensures that tasks wipe their next_method and next_kwargs for the configured states: | |
Test that ensures that tasks wipe their next_method and next_kwargs when the TI enters one of the following states: |
@jedcunningham @uranusjr I needed to slightly modify some of the code due to a mypy check that was not present when this PR was originally opened. Please review again and let me know if any changes are needed before merging. Thanks! |
tests/models/test_taskinstance.py
Outdated
_python_callable = failure | ||
_retries = 1 | ||
_retry_delay = datetime.timedelta(seconds=2) | ||
def _raise_af_exception(exception_type): |
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.
def _raise_af_exception(exception_type): | |
def _raise_if_exception(exception_type): |
Probably? Or does af
stand for Airflow?
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.
af
stands for Airflow. However, _raise_if_exception
better describes the function. I will update this, thanks.
tests/models/test_taskinstance.py
Outdated
@@ -537,10 +519,10 @@ def reschedule(): | |||
session.commit() | |||
|
|||
ti.task = task | |||
if state in [State.FAILED, State.UP_FOR_RETRY]: | |||
if exception_type == AirflowException: |
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.
This does not correctly cover the AirflowRescheduleException(timezone.utcnow())
case. It’s probably better to change exception_type
to exception
instead and always instantiate to avoid this subtle issue caused by exception_type
may be either a type or an instance.
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.
Thanks for the feedback, I will rename exception_type
to exception
. I will edit as follows:
if state in [State.FAILED, State.UP_FOR_RETRY]:
with pytest.raises(exception):
ti.run()
else:
ti.run()
This ensures that the exception
is tied to whatever state
is being checked.
The reason I did not include AirflowRescheduleException(timezone.utcnow())
is because that exception is caught during ti.run()
.
…ion directly to _raise_if_exception, and checked state vs. exception when running pytest.raises.
related: #19120
Refactoring tests introduced in #19183.