insomnes commented on PR #46268:
URL: https://github.com/apache/airflow/pull/46268#issuecomment-2626000545

   The mentioned bug in the spark k8s operator test is related to mocking and 
new changes. 
   
   Previously, tests were performed because the new KPO `execute()` validates 
the name set for a pod on an operator by calling `_set_name` (because of 
templating changes, we need to have context applied to templates before name 
validation).
   Thus the tests in k8s spark operator with `mock_create_job_name` could not 
succeed. MagickMock is not a str instance, so validation failed.
   
   This led me to understand that calls to `assert op.name.startswith("...")` 
are broken in this test, otherwise they would fail too (this is checked after 
operator execution). My investigation showed that changing prefix to anything 
like `name.startswith("ABRA-CADABRA")` didn't lead to test fails. Functions 
with applied `unittest.patch`  actually return `MagicMock` object, so the 
`op.name` was a `MagicMock` instance in these tests.
   
   Any method call on such an object doesn't fail by design and returns another 
`MagicMock` object. They lead to positive assertions. That's why I have 
refactored affected spark k8s operator tests. I've extracted 
`create_application` tests to a separate class where `create_job_name` is not 
patched. 


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