@@ -1915,7 +1915,7 @@ class TestShortCircuitWithTeardown:
1915
1915
def test_short_circuit_with_teardowns (
1916
1916
self , dag_maker , ignore_downstream_trigger_rules , should_skip , with_teardown , expected
1917
1917
):
1918
- with dag_maker () as dag :
1918
+ with dag_maker (serialized = True ) :
1919
1919
op1 = ShortCircuitOperator (
1920
1920
task_id = "op1" ,
1921
1921
python_callable = lambda : not should_skip ,
@@ -1928,21 +1928,20 @@ def test_short_circuit_with_teardowns(
1928
1928
op4 .as_teardown ()
1929
1929
op1 >> op2 >> op3 >> op4
1930
1930
op1 .skip = MagicMock ()
1931
- dagrun = dag_maker .create_dagrun ()
1932
- tis = dagrun .get_task_instances ()
1933
- ti : TaskInstance = next (x for x in tis if x .task_id == "op1" )
1934
- ti ._run_raw_task ()
1935
- expected_tasks = {dag .task_dict [x ] for x in expected }
1931
+ dagrun = dag_maker .create_dagrun ()
1932
+ tis = dagrun .get_task_instances ()
1933
+ ti : TaskInstance = next (x for x in tis if x .task_id == "op1" )
1934
+ ti ._run_raw_task ()
1936
1935
if should_skip :
1937
1936
# we can't use assert_called_with because it's a set and therefore not ordered
1938
- actual_skipped = set (op1 .skip .call_args .kwargs ["tasks" ])
1939
- assert actual_skipped == expected_tasks
1937
+ actual_skipped = set (x . task_id for x in op1 .skip .call_args .kwargs ["tasks" ])
1938
+ assert actual_skipped == set ( expected )
1940
1939
else :
1941
1940
op1 .skip .assert_not_called ()
1942
1941
1943
1942
@pytest .mark .parametrize ("config" , ["sequence" , "parallel" ])
1944
1943
def test_short_circuit_with_teardowns_complicated (self , dag_maker , config ):
1945
- with dag_maker ():
1944
+ with dag_maker (serialized = True ):
1946
1945
s1 = PythonOperator (task_id = "s1" , python_callable = print ).as_setup ()
1947
1946
s2 = PythonOperator (task_id = "s2" , python_callable = print ).as_setup ()
1948
1947
op1 = ShortCircuitOperator (
@@ -1959,16 +1958,16 @@ def test_short_circuit_with_teardowns_complicated(self, dag_maker, config):
1959
1958
else :
1960
1959
raise ValueError ("unexpected" )
1961
1960
op1 .skip = MagicMock ()
1962
- dagrun = dag_maker .create_dagrun ()
1963
- tis = dagrun .get_task_instances ()
1964
- ti : TaskInstance = next (x for x in tis if x .task_id == "op1" )
1965
- ti ._run_raw_task ()
1966
- # we can't use assert_called_with because it's a set and therefore not ordered
1967
- actual_skipped = set (op1 .skip .call_args .kwargs ["tasks" ])
1968
- assert actual_skipped == {s2 , op2 }
1961
+ dagrun = dag_maker .create_dagrun ()
1962
+ tis = dagrun .get_task_instances ()
1963
+ ti : TaskInstance = next (x for x in tis if x .task_id == "op1" )
1964
+ ti ._run_raw_task ()
1965
+ # we can't use assert_called_with because it's a set and therefore not ordered
1966
+ actual_skipped = set (op1 .skip .call_args .kwargs ["tasks" ])
1967
+ assert actual_skipped == {s2 , op2 }
1969
1968
1970
1969
def test_short_circuit_with_teardowns_complicated_2 (self , dag_maker ):
1971
- with dag_maker ():
1970
+ with dag_maker (serialized = True ):
1972
1971
s1 = PythonOperator (task_id = "s1" , python_callable = print ).as_setup ()
1973
1972
s2 = PythonOperator (task_id = "s2" , python_callable = print ).as_setup ()
1974
1973
op1 = ShortCircuitOperator (
@@ -1986,22 +1985,22 @@ def test_short_circuit_with_teardowns_complicated_2(self, dag_maker):
1986
1985
# in this case we don't want to skip t2 since it should run
1987
1986
op1 >> t2
1988
1987
op1 .skip = MagicMock ()
1989
- dagrun = dag_maker .create_dagrun ()
1990
- tis = dagrun .get_task_instances ()
1991
- ti : TaskInstance = next (x for x in tis if x .task_id == "op1" )
1992
- ti ._run_raw_task ()
1993
- # we can't use assert_called_with because it's a set and therefore not ordered
1994
- actual_kwargs = op1 .skip .call_args .kwargs
1995
- actual_skipped = set (actual_kwargs ["tasks" ])
1996
- assert actual_skipped == {op3 }
1988
+ dagrun = dag_maker .create_dagrun ()
1989
+ tis = dagrun .get_task_instances ()
1990
+ ti : TaskInstance = next (x for x in tis if x .task_id == "op1" )
1991
+ ti ._run_raw_task ()
1992
+ # we can't use assert_called_with because it's a set and therefore not ordered
1993
+ actual_kwargs = op1 .skip .call_args .kwargs
1994
+ actual_skipped = set (actual_kwargs ["tasks" ])
1995
+ assert actual_skipped == {op3 }
1997
1996
1998
1997
@pytest .mark .parametrize ("level" , [logging .DEBUG , logging .INFO ])
1999
1998
def test_short_circuit_with_teardowns_debug_level (self , dag_maker , level , clear_db ):
2000
1999
"""
2001
2000
When logging is debug we convert to a list to log the tasks skipped
2002
2001
before passing them to the skip method.
2003
2002
"""
2004
- with dag_maker ():
2003
+ with dag_maker (serialized = True ):
2005
2004
s1 = PythonOperator (task_id = "s1" , python_callable = print ).as_setup ()
2006
2005
s2 = PythonOperator (task_id = "s2" , python_callable = print ).as_setup ()
2007
2006
op1 = ShortCircuitOperator (
@@ -2020,18 +2019,18 @@ def test_short_circuit_with_teardowns_debug_level(self, dag_maker, level, clear_
2020
2019
# in this case we don't want to skip t2 since it should run
2021
2020
op1 >> t2
2022
2021
op1 .skip = MagicMock ()
2023
- dagrun = dag_maker .create_dagrun ()
2024
- tis = dagrun .get_task_instances ()
2025
- ti : TaskInstance = next (x for x in tis if x .task_id == "op1" )
2026
- ti ._run_raw_task ()
2027
- # we can't use assert_called_with because it's a set and therefore not ordered
2028
- actual_kwargs = op1 .skip .call_args .kwargs
2029
- actual_skipped = actual_kwargs ["tasks" ]
2030
- if level <= logging .DEBUG :
2031
- assert isinstance (actual_skipped , list )
2032
- else :
2033
- assert isinstance (actual_skipped , Generator )
2034
- assert set (actual_skipped ) == {op3 }
2022
+ dagrun = dag_maker .create_dagrun ()
2023
+ tis = dagrun .get_task_instances ()
2024
+ ti : TaskInstance = next (x for x in tis if x .task_id == "op1" )
2025
+ ti ._run_raw_task ()
2026
+ # we can't use assert_called_with because it's a set and therefore not ordered
2027
+ actual_kwargs = op1 .skip .call_args .kwargs
2028
+ actual_skipped = actual_kwargs ["tasks" ]
2029
+ if level <= logging .DEBUG :
2030
+ assert isinstance (actual_skipped , list )
2031
+ else :
2032
+ assert isinstance (actual_skipped , Generator )
2033
+ assert set (actual_skipped ) == {op3 }
2035
2034
2036
2035
2037
2036
@pytest .mark .parametrize (
0 commit comments