potiuk commented on code in PR #28631:
URL: https://github.com/apache/airflow/pull/28631#discussion_r1058622999


##########
tests/providers/conftest.py:
##########
@@ -0,0 +1,75 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+from __future__ import annotations
+
+import pytest
+
+from tests.test_utils import db
+
+# Providers with subpackages
+INNER_PROVIDERS = {

Review Comment:
   You convinced me.
   
   I just tested your solution (My videos were with --with-db-init) and yes. I 
agree it's not noticeable in PyCharm/IntelliJ, so you are likely right that 
Flask import and others add a lot. And yeah. Having DB reset in this case for 
every test is quite OK. It is actually likely that those flask imports cause 
the constraint problems anyway.
   
   Ttry to notice which one is which (it's visible, but barely).
   
   
https://user-images.githubusercontent.com/595491/209874550-732ee92c-43dc-4fc1-b3f7-f0b365b0d281.mov
   
   
https://user-images.githubusercontent.com/595491/209874540-7a7e5611-d888-45a8-b8fd-02f8df147385.mov
   
   And it has the nice benefit that it will help the users in many situations 
where they run single tests as well. This overhead is much smallee that I was 
used to from `--with-db-init` 
   
   However, I think few changes are needed:
   
   1) have a "clear_all()" in the test_utils.db and using it instead of having 
the list of methods in conftest.py  - this will help with future maintainability
   
   2) What's even more ... I **really** think we should apply it to all tests 
and completely apply it to the main conftest.py and do it for all modules - I 
think with such low overhead we can kill few birds with the same stone and the 
overall overhead will be miinimal. I just did this in main "conftest.py". I 
don't think we need to detect any providers at all and run it for **everything**
   
   ```
   @pytest.fixture(scope="module", autouse=True)
   def _clear_db_between_modules(request):
       from tests.test_utils import db
   
       """Clear DB between each separate provider package test runs."""
       print("!!!!!!!!Clearing DB!!!!!!!!")
       db.clear_db_runs()
       db.clear_db_datasets()
       db.clear_db_dags()
       db.clear_db_serialized_dags()
       db.clear_db_sla_miss()
       db.clear_db_pools()
       db.clear_db_connections()
       db.clear_db_variables()
       db.clear_db_dag_code()
       db.clear_db_callbacks()
       db.clear_rendered_ti_fields()
       db.clear_db_import_errors()
       db.clear_db_dag_warnings()
       db.clear_db_xcom()
       db.clear_db_logs()
       db.clear_db_jobs()
       db.clear_db_task_fail()
       db.clear_db_task_reschedule()
       db.clear_dag_specific_permissions()
       db.create_default_connections()
       db.set_default_pool_slots(128)
       yield
   ```
   
   And run it with -s 
   
   ```
   pytest -s tests/cli/ tests/core/
   ```
   
   And it looks like it works as expected:
   
   ```
   
tests/cli/commands/test_info_command.py::TestPiiAnonymizer::test_should_remove_pii_from_path
 !!!!!!!!Clearing DB!!!!!!!!
   PASSED
   
tests/cli/commands/test_info_command.py::TestPiiAnonymizer::test_should_remove_pii_from_url[postgresql+psycopg2://postgres:airflow@postgres/airflow-postgresql+psycopg2://p...s:PASSWORD@postgres/airflow]
 PASSED
   
tests/cli/commands/test_info_command.py::TestPiiAnonymizer::test_should_remove_pii_from_url[postgresql+psycopg2://postgres@postgres/airflow-postgresql+psycopg2://p...s@postgres/airflow]
 PASSED
   
tests/cli/commands/test_info_command.py::TestPiiAnonymizer::test_should_remove_pii_from_url[postgresql+psycopg2://:airflow@postgres/airflow-postgresql+psycopg2://:PASSWORD@postgres/airflow]
 PASSED
   
tests/cli/commands/test_info_command.py::TestPiiAnonymizer::test_should_remove_pii_from_url[postgresql+psycopg2://postgres/airflow-postgresql+psycopg2://postgres/airflow]
 PASSED
   tests/cli/commands/test_info_command.py::TestAirflowInfo::test_airflow_info 
PASSED
   tests/cli/commands/test_info_command.py::TestAirflowInfo::test_system_info 
PASSED
   tests/cli/commands/test_info_command.py::TestAirflowInfo::test_paths_info 
PASSED
   tests/cli/commands/test_info_command.py::TestAirflowInfo::test_tools_info 
PASSED
   tests/cli/commands/test_info_command.py::TestAirflowInfo::test_show_info 
PASSED
   
tests/cli/commands/test_info_command.py::TestAirflowInfo::test_show_info_anonymize
 PASSED
   
tests/cli/commands/test_info_command.py::TestInfoCommandMockHttpx::test_show_info_anonymize_fileio
 PASSED
   
tests/cli/commands/test_jobs_command.py::TestCliConfigList::test_should_report_success_for_one_working_scheduler
 !!!!!!!!Clearing DB!!!!!!!!
   PASSED
   ```



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