ivanwakeup opened a new issue, #38944:
URL: https://github.com/apache/airflow/issues/38944

   ### What do you see as an issue?
   
   The airflow Best Practices documentation page suggests using 
`unittest.mock.patch` along with setting `os.environ` values to mock Variables 
and Connections. This doesn't seem to work in practice (testing against airflow 
2.8.1)--airflow attempts to read Variable values from variable table in DB 
instead of using `os.environ` overrides.
   
   
   
   ### Solving the problem
   
   example non-working code:
   
   ```
   from unittest.mock import patch
   from airflow.models import Variable
   
   def test_variable_fetch():
       with patch.dict('os.environ', AIRFLOW_VAR_my_test_var="my_test_value"):
           print(Variable.get("my_test_var"))
   ```
   
   ### Anything else
   
   
https://airflow.apache.org/docs/apache-airflow/2.8.4/best-practices.html#mocking-variables-and-connections
 - guide page in question
   
   ### Are you willing to submit PR?
   
   - [ ] Yes I am willing to submit a PR!
   
   ### Code of Conduct
   
   - [X] I agree to follow this project's [Code of 
Conduct](https://github.com/apache/airflow/blob/main/CODE_OF_CONDUCT.md)
   


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