Skip to content

Commit 2b77043

Browse files
xchwanrawwar
andauthored
Enable PT006 rule to airflow-core tests (security, lineage, jobs, executors, datasets) (#57913)
Co-authored-by: Kalyan R <kalyan.ben10@live.com>
1 parent 33b4d40 commit 2b77043

8 files changed

Lines changed: 30 additions & 30 deletions

File tree

airflow-core/tests/unit/datasets/test_dataset.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323

2424
@pytest.mark.parametrize(
25-
"module_path, attr_name, expected_value, warning_message",
25+
("module_path", "attr_name", "expected_value", "warning_message"),
2626
(
2727
pytest.param(
2828
"airflow",

airflow-core/tests/unit/executors/test_base_executor.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ def test_gauge_executor_metrics_single_executor(mock_stats_gauge, mock_trigger_t
125125

126126

127127
@pytest.mark.parametrize(
128-
"executor_class, executor_name",
128+
("executor_class", "executor_name"),
129129
[(LocalExecutor, "LocalExecutor")],
130130
)
131131
@mock.patch("airflow.executors.local_executor.LocalExecutor.sync")
@@ -285,7 +285,7 @@ def test_parser_add_command(mock_add_command, mock_get_cli_command):
285285
mock_add_command.assert_called_once()
286286

287287

288-
@pytest.mark.parametrize("loop_duration, total_tries", [(0.5, 12), (1.0, 7), (1.7, 4), (10, 2)])
288+
@pytest.mark.parametrize(("loop_duration", "total_tries"), [(0.5, 12), (1.0, 7), (1.7, 4), (10, 2)])
289289
def test_running_retry_attempt_type(loop_duration, total_tries):
290290
"""
291291
Verify can_try_again returns True until at least 5 seconds have passed.

airflow-core/tests/unit/executors/test_local_executor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ def test_clean_stop_on_signal(self):
169169
executor.end()
170170

171171
@pytest.mark.parametrize(
172-
["conf_values", "expected_server"],
172+
("conf_values", "expected_server"),
173173
[
174174
(
175175
{

airflow-core/tests/unit/jobs/test_base_job.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def abort():
9494
assert job.end_date is not None
9595

9696
@pytest.mark.parametrize(
97-
"job_runner, job_type,job_heartbeat_sec",
97+
("job_runner", "job_type", "job_heartbeat_sec"),
9898
[(SchedulerJobRunner, "scheduler", "11"), (TriggererJobRunner, "triggerer", "9")],
9999
)
100100
def test_heart_rate_after_fetched_from_db(self, job_runner, job_type, job_heartbeat_sec):
@@ -116,7 +116,7 @@ def test_heart_rate_after_fetched_from_db(self, job_runner, job_type, job_heartb
116116
session.rollback()
117117

118118
@pytest.mark.parametrize(
119-
"job_runner, job_type,job_heartbeat_sec",
119+
("job_runner", "job_type", "job_heartbeat_sec"),
120120
[(SchedulerJobRunner, "scheduler", "11"), (TriggererJobRunner, "triggerer", "9")],
121121
)
122122
def test_heart_rate_via_constructor_persists(self, job_runner, job_type, job_heartbeat_sec):

airflow-core/tests/unit/jobs/test_scheduler_job.py

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -950,7 +950,7 @@ def test_find_executable_task_instances_pool(self, dag_maker):
950950
session.rollback()
951951

952952
@pytest.mark.parametrize(
953-
"state, total_executed_ti",
953+
("state", "total_executed_ti"),
954954
[
955955
(DagRunState.SUCCESS, 0),
956956
(DagRunState.FAILED, 0),
@@ -1824,7 +1824,7 @@ def test_enqueue_task_instances_sets_ti_state_to_None_if_dagrun_in_finish_state(
18241824
mock_queue_workload.assert_not_called()
18251825

18261826
@pytest.mark.parametrize(
1827-
"task1_exec, task2_exec",
1827+
("task1_exec", "task2_exec"),
18281828
[
18291829
("default_exec", "default_exec"),
18301830
("default_exec", "secondary_exec"),
@@ -1967,7 +1967,7 @@ def _create_dagruns():
19671967
assert ti.state == State.QUEUED
19681968

19691969
@pytest.mark.parametrize(
1970-
"task1_exec, task2_exec",
1970+
("task1_exec", "task2_exec"),
19711971
[
19721972
("default_exec", "default_exec"),
19731973
("default_exec", "secondary_exec"),
@@ -2106,7 +2106,7 @@ def _create_dagruns():
21062106
session.rollback()
21072107

21082108
@pytest.mark.parametrize(
2109-
"task1_exec, task2_exec",
2109+
("task1_exec", "task2_exec"),
21102110
[
21112111
("default_exec", "default_exec"),
21122112
("default_exec", "secondary_exec"),
@@ -2641,7 +2641,7 @@ def test_runs_are_created_after_max_active_runs_was_reached(self, dag_maker, ses
26412641
assert len(dag_runs) == 2
26422642

26432643
@pytest.mark.parametrize(
2644-
"ti_state, final_ti_span_status",
2644+
("ti_state", "final_ti_span_status"),
26452645
[
26462646
pytest.param(State.SUCCESS, SpanStatus.ENDED, id="dr_ended_successfully"),
26472647
pytest.param(State.RUNNING, SpanStatus.ACTIVE, id="dr_still_running"),
@@ -2766,7 +2766,7 @@ def test_end_spans_of_externally_ended_ops(self, dag_maker):
27662766
assert self.job_runner.active_spans.get("ti:" + ti.id) is None
27672767

27682768
@pytest.mark.parametrize(
2769-
"state, final_span_status",
2769+
("state", "final_span_status"),
27702770
[
27712771
pytest.param(State.SUCCESS, SpanStatus.ENDED, id="dr_ended_successfully"),
27722772
pytest.param(State.RUNNING, SpanStatus.NEEDS_CONTINUANCE, id="dr_still_running"),
@@ -2956,7 +2956,7 @@ def test_dagrun_timeout_fails_run_and_update_next_dagrun(self, dag_maker):
29562956
)
29572957

29582958
@pytest.mark.parametrize(
2959-
"state, expected_callback_msg", [(State.SUCCESS, "success"), (State.FAILED, "task_failure")]
2959+
("state", "expected_callback_msg"), [(State.SUCCESS, "success"), (State.FAILED, "task_failure")]
29602960
)
29612961
def test_dagrun_callbacks_are_called(self, state, expected_callback_msg, dag_maker, session):
29622962
"""
@@ -3001,7 +3001,7 @@ def test_dagrun_callbacks_are_called(self, state, expected_callback_msg, dag_mak
30013001
session.close()
30023002

30033003
@pytest.mark.parametrize(
3004-
"state, expected_callback_msg", [(State.SUCCESS, "success"), (State.FAILED, "task_failure")]
3004+
("state", "expected_callback_msg"), [(State.SUCCESS, "success"), (State.FAILED, "task_failure")]
30053005
)
30063006
def test_dagrun_plugins_are_notified(self, state, expected_callback_msg, dag_maker, session):
30073007
"""
@@ -3156,7 +3156,7 @@ def test_dagrun_callbacks_are_not_added_when_callbacks_are_not_defined(self, sta
31563156

31573157
session.rollback()
31583158

3159-
@pytest.mark.parametrize("state, msg", [[State.SUCCESS, "success"], [State.FAILED, "task_failure"]])
3159+
@pytest.mark.parametrize(("state", "msg"), [[State.SUCCESS, "success"], [State.FAILED, "task_failure"]])
31603160
def test_dagrun_callbacks_are_added_when_callbacks_are_defined(self, state, msg, dag_maker):
31613161
"""
31623162
Test if on_*_callback are defined on DAG, Callbacks ARE registered and sent to DAG Processor
@@ -3278,7 +3278,7 @@ def test_do_not_schedule_removed_task(self, dag_maker, session):
32783278
assert len(new_tis) == 0
32793279

32803280
@pytest.mark.parametrize(
3281-
"ti_states, run_state",
3281+
("ti_states", "run_state"),
32823282
[
32833283
(["failed", "success"], "failed"),
32843284
(["success", "success"], "success"),
@@ -4257,7 +4257,7 @@ def test_should_update_dag_next_dagruns(self, provide_run_count: bool, kwargs: d
42574257
assert actual == should_update
42584258

42594259
@pytest.mark.parametrize(
4260-
"run_type, expected",
4260+
("run_type", "expected"),
42614261
[
42624262
(DagRunType.MANUAL, False),
42634263
(DagRunType.SCHEDULED, True),
@@ -4498,7 +4498,7 @@ def dict_from_obj(obj):
44984498

44994499
@pytest.mark.need_serialized_dag
45004500
@pytest.mark.parametrize(
4501-
"disable, enable",
4501+
("disable", "enable"),
45024502
[
45034503
pytest.param({"is_stale": True}, {"is_stale": False}, id="active"),
45044504
pytest.param({"is_paused": True}, {"is_paused": False}, id="paused"),
@@ -5613,7 +5613,7 @@ def _running_counts():
56135613
assert session.scalar(select(func.count()).where(DagRun.dag_id == dag1_dag_id)) == 36
56145614

56155615
@pytest.mark.parametrize(
5616-
"pause_it, expected_running",
5616+
("pause_it", "expected_running"),
56175617
[
56185618
(True, 0),
56195619
(False, 3),
@@ -5820,7 +5820,7 @@ def test_no_dagruns_would_stuck_in_running(self, dag_maker):
58205820
assert DagRun.find(run_id="dr1_run_2")[0].state == State.RUNNING
58215821

58225822
@pytest.mark.parametrize(
5823-
"state, start_date, end_date",
5823+
("state", "start_date", "end_date"),
58245824
[
58255825
[State.NONE, None, None],
58265826
[
@@ -5862,7 +5862,7 @@ def test_dag_file_processor_process_task_instances(self, state, start_date, end_
58625862
assert ti.state == State.SCHEDULED
58635863

58645864
@pytest.mark.parametrize(
5865-
"state,start_date,end_date",
5865+
("state", "start_date", "end_date"),
58665866
[
58675867
[State.NONE, None, None],
58685868
[
@@ -5908,7 +5908,7 @@ def test_dag_file_processor_process_task_instances_with_max_active_tis_per_dag(
59085908
assert ti.state == State.SCHEDULED
59095909

59105910
@pytest.mark.parametrize(
5911-
"state,start_date,end_date",
5911+
("state", "start_date", "end_date"),
59125912
[
59135913
[State.NONE, None, None],
59145914
[
@@ -5954,7 +5954,7 @@ def test_dag_file_processor_process_task_instances_with_max_active_tis_per_dagru
59545954
assert ti.state == State.SCHEDULED
59555955

59565956
@pytest.mark.parametrize(
5957-
"state, start_date, end_date",
5957+
("state", "start_date", "end_date"),
59585958
[
59595959
[State.NONE, None, None],
59605960
[
@@ -6712,7 +6712,7 @@ def test_asset_orphaning_ignore_orphaned_assets(self, dag_maker, session):
67126712
assert [asset.updated_at for asset in orphaned] == updated_at_timestamps
67136713

67146714
@pytest.mark.parametrize(
6715-
"paused, stale, expected_classpath",
6715+
("paused", "stale", "expected_classpath"),
67166716
[
67176717
pytest.param(
67186718
False,
@@ -6931,7 +6931,7 @@ def test_scheduler_passes_context_from_server_on_heartbeat_timeout(self, dag_mak
69316931
assert callback_request.context_from_server.max_tries == ti.max_tries
69326932

69336933
@pytest.mark.parametrize(
6934-
"retries,callback_kind,expected",
6934+
("retries", "callback_kind", "expected"),
69356935
[
69366936
(1, "retry", TaskInstanceState.UP_FOR_RETRY),
69376937
(0, "failure", TaskInstanceState.FAILED),
@@ -7178,7 +7178,7 @@ def per_test(self) -> Generator:
71787178
self.clean_db()
71797179

71807180
@pytest.mark.parametrize(
7181-
"expected_query_count, dag_count, task_count",
7181+
("expected_query_count", "dag_count", "task_count"),
71827182
[
71837183
(21, 1, 1), # One DAG with one task per DAG file.
71847184
(21, 1, 5), # One DAG with five tasks per DAG file.
@@ -7244,7 +7244,7 @@ def test_execute_queries_count_with_harvested_dags(
72447244

72457245
@pytest.mark.flaky(reruns=3, reruns_delay=5)
72467246
@pytest.mark.parametrize(
7247-
"expected_query_counts, dag_count, task_count, start_ago, schedule, shape",
7247+
("expected_query_counts", "dag_count", "task_count", "start_ago", "schedule", "shape"),
72487248
[
72497249
# One DAG with one task per DAG file.
72507250
([10, 10, 10, 10], 1, 1, "1d", "None", "no_structure"),

airflow-core/tests/unit/jobs/test_triggerer_job.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ def send_msg_spy(self, msg, *args, **kwargs):
279279

280280

281281
@pytest.mark.parametrize(
282-
"trigger, watcher_count, trigger_count",
282+
("trigger", "watcher_count", "trigger_count"),
283283
[
284284
(TimeDeltaTrigger(datetime.timedelta(days=7)), 0, 1),
285285
(FileDeleteTrigger("/tmp/foo.txt", poke_interval=1), 1, 0),

airflow-core/tests/unit/lineage/test_hook.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ class FakePlugin(plugins_manager.AirflowPlugin):
206206

207207

208208
@pytest.mark.parametrize(
209-
"has_readers, expected_class",
209+
("has_readers", "expected_class"),
210210
[
211211
(True, HookLineageCollector),
212212
(False, NoOpCollector),

airflow-core/tests/unit/security/test_kerberos.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
class TestKerberos:
3535
@pytest.mark.parametrize(
36-
"kerberos_config, expected_cmd",
36+
("kerberos_config", "expected_cmd"),
3737
[
3838
(
3939
{("kerberos", "reinit_frequency"): "42"},

0 commit comments

Comments
 (0)