potiuk commented on PR #30588:
URL: https://github.com/apache/airflow/pull/30588#issuecomment-1511512047

    Going back to the PR that caused test failures on our self-hosted runners 
after succeeding on public runners.  
https://github.com/apache/airflow/pull/30362 (which we had to revert).
   
   This is an interesting one.
   
   I figured that one @vincbeck @shahar1 @uranusjr . I know why the tests were 
failing on self-hosted, I am not 100% sure  though why they were not failing in 
the public runners, but I have a theory.
   
   The problem was a side effect of the new `test_except_value_error` (from 
`tests/operators/test_python.py`) on few other tests, namely monkeypatching the 
loads method of pickle library with mock throwing DeserializationErro:
   
   ```` python 
       def test_except_value_error(self):
           ...
           task.pickling_library.loads = 
mock.Mock(side_effect=DeserializingResultError)  # <- THIS was the problem
           with pytest.raises(DeserializingResultError):
               task._read_result(path=mock.Mock())
   ````
   
   I changed it to this and it fixed the problem:
   
   ```python
       @mock.patch("pickle.loads") # <- this will restore the monkey patched 
method after test completes
       def test_except_value_error(self, loads_mock):
           ...
   
           loads_mock.side_effect = DeserializingResultError
           with pytest.raises(DeserializingResultError):
               task._read_result(path=mock.Mock())
   
   ```
   
   The thing was that picklling library is a module - either `pickle` or `dill` 
and monkeypatchign `loads` library there, monkeypatched it also for any of the 
tests run within the same interpreter.  Default is `pickle`, so subsequent 
tests that used the same "pickle" library used the same monkeypatched loads 
method that threw DeserializationError. 
   
   Now, I am not 100% sure why it has not failed on public runners. But I have 
a theory.
   
   The way how `pytest` manage the modules and whether it keeps them in memory 
between the tests is a bit of mystery to me (I've hit a few times somewhat 
strange behaviour with objects kept in memory), but a theory  I have is that if 
the tests were run in memory constrained environment, the loaded  module with 
monkeypatched method was removed before the "test_external_python" was run in 
the "decorators" pckages run - that would explain why the tests were not 
failing in Public runners. 
   
   Anyone has another theory ?


-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to