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

   > The way I see it is, if the stacktrace where the session has been created 
contains one test file, it means the session has been created in tests?
   
   Not really - the difficulty is that "all" tested code is called from tests. 
Say we want to do 
   
   ```
   def test_something:
        # some setup here (here we want to use DB calls
        db.clean()
        # actual test here (here we want to use internal API
        ti.run()
   ```
   
   And we need to guess when we have the second case (i.e. when we are already 
running "tested" code.
   
   When you use fixtures to setup code - it's easy - we do it by checking 
`conftest.py` in the stacktrace, but if someone mixes tests and setup code in 
test method, we can only guess. There are cases like baseoperator.run() which 
is used only in CLI and tests and until you go to "_run_raw_task", it should 
use DB, but after that internal api calls (we already handle that by the 
special  clause. We could potentially extend the list of calls that we consider 
as "test setup" when called directly from tests. But in general - the whole 
detection is rather brittle.


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