You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2019/07/15 10:17:00 UTC

[GitHub] [airflow] ashb commented on issue #5570: [AIRFLOW-4939] Add default_task_retries config

ashb commented on issue #5570: [AIRFLOW-4939] Add default_task_retries config
URL: https://github.com/apache/airflow/pull/5570#issuecomment-511346942
 
 
   ```
   ======================================================================
   56) FAIL: test_default_retries (tests.operators.test_bash_operator.BashOperatorTest)
   ----------------------------------------------------------------------
      Traceback (most recent call last):
       /usr/lib/python3.5/unittest/mock.py line 1157 in patched
         return func(*args, **keywargs)
       tests/operators/test_bash_operator.py line 124 in test_default_retries
         self.assertEqual(bash_operator.retries, 3)
      AssertionError: 0 != 3
   ```
   
   You still have the problem that python evaulates the default value ones at the time the module is first loaded so you will need to do something like [importlib.reload](https://docs.python.org/3/library/importlib.html#importlib.reload)
   
   ```python
       @mock.patch.object(configuration.conf, 'getint')
       def test_task_retries(self, mock_config):
           mock_config.return_value = '3'
           importlib.reload(airflow.operators.bash_operator)
           bash_operator = BashOperator(
               bash_command='echo "stdout"',
               task_id='test_task_retries',
               retries=2,
               dag=None
           )
   
           self.assertEqual(bash_operator.retries, 2)
   ```
   
   And similar for the other tests you add. We should also add:
   
   ```python
       @classmethod
       def tearDownClass(cls):
               importlib.reload(airflow.operators.bash_operator)
   ```
   
   to reset the default back to the default for any other tests.
   
   Not that you will need to import the "whole" module to get the _module object_ to pass to `reload()`
   

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services