You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2022/03/04 05:50:51 UTC

[GitHub] [airflow] dstandish opened a new pull request #21983: Simplify tests for CLI connections commands

dstandish opened a new pull request #21983:
URL: https://github.com/apache/airflow/pull/21983


   The tests (particularly with the export subcommand) were doing a fair bit of unnecessary mocking.  In particular they mocked `builtins.open`.  But there's no good reason that we can't actually write out the file and read the file in the assert (which is a much better way to test this).
   
   I suspect the reason that the author did this is because the file wasn't _closed_, so when you read the value from the exported file (if the process has not been exited) then the buffer may not be fully written to disk.  I fix this by closing the file after writing the connections.
   
   As part of this change I also update to use current pytest techniques for parameterization and setup / teardown.
   
   <!--
   Thank you for contributing! Please make sure that your code changes
   are covered with tests. And in case of new features or big changes
   remember to adjust the documentation.
   
   Feel free to ping committers for the review!
   
   In case of existing issue, reference it using one of the following:
   
   closes: #ISSUE
   related: #ISSUE
   
   How to write a good git commit message:
   http://chris.beams.io/posts/git-commit/
   -->
   
   ---
   **^ Add meaningful description above**
   
   Read the **[Pull Request Guidelines](https://github.com/apache/airflow/blob/main/CONTRIBUTING.rst#pull-request-guidelines)** for more information.
   In case of fundamental code change, Airflow Improvement Proposal ([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvements+Proposals)) is needed.
   In case of a new dependency, check compliance with the [ASF 3rd Party License Policy](https://www.apache.org/legal/resolved.html#category-x).
   In case of backwards incompatible changes please leave a note in [UPDATING.md](https://github.com/apache/airflow/blob/main/UPDATING.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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] dstandish commented on a change in pull request #21983: Simplify tests for CLI connections commands

Posted by GitBox <gi...@apache.org>.
dstandish commented on a change in pull request #21983:
URL: https://github.com/apache/airflow/pull/21983#discussion_r819301689



##########
File path: tests/cli/commands/test_connection_command.py
##########
@@ -34,13 +32,11 @@
 from tests.test_utils.db import clear_db_connections
 
 
-class TestCliGetConnection(unittest.TestCase):
-    def setUp(self):
-        self.parser = cli_parser.get_parser()
-        clear_db_connections()
+class TestCliGetConnection:
+    parser = cli_parser.get_parser()
 
-    def tearDown(self):
-        clear_db_connections()
+    def setup_method(self):
+        clear_db_connections(add_default_connections_back=True)

Review comment:
       no because there are 4 (or more?) classes and this will apply to all of them... right?




-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] dstandish commented on a change in pull request #21983: Simplify tests for CLI connections commands

Posted by GitBox <gi...@apache.org>.
dstandish commented on a change in pull request #21983:
URL: https://github.com/apache/airflow/pull/21983#discussion_r819299829



##########
File path: tests/cli/commands/test_connection_command.py
##########
@@ -34,13 +32,11 @@
 from tests.test_utils.db import clear_db_connections
 
 
-class TestCliGetConnection(unittest.TestCase):
-    def setUp(self):
-        self.parser = cli_parser.get_parser()
-        clear_db_connections()
+class TestCliGetConnection:
+    parser = cli_parser.get_parser()
 
-    def tearDown(self):
-        clear_db_connections()
+    def setup_method(self):
+        clear_db_connections(add_default_connections_back=True)

Review comment:
       yeah i was thinking about that
   
   maybe an autouse fixture in the module that clears after yield
   
   they could all use same fixture except that only some of the classes require the example connectios




-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] uranusjr commented on a change in pull request #21983: Simplify tests for CLI connections commands

Posted by GitBox <gi...@apache.org>.
uranusjr commented on a change in pull request #21983:
URL: https://github.com/apache/airflow/pull/21983#discussion_r819301275



##########
File path: tests/cli/commands/test_connection_command.py
##########
@@ -34,13 +32,11 @@
 from tests.test_utils.db import clear_db_connections
 
 
-class TestCliGetConnection(unittest.TestCase):
-    def setUp(self):
-        self.parser = cli_parser.get_parser()
-        clear_db_connections()
+class TestCliGetConnection:
+    parser = cli_parser.get_parser()
 
-    def tearDown(self):
-        clear_db_connections()
+    def setup_method(self):
+        clear_db_connections(add_default_connections_back=True)

Review comment:
       Isn’t that essentially the same as
   
   ```python
   def teardown_method(self):
       clear_db_connections(add_default_connections_back=False)
   ```
   
   but more code?




-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] dstandish commented on a change in pull request #21983: Simplify tests for CLI connections commands

Posted by GitBox <gi...@apache.org>.
dstandish commented on a change in pull request #21983:
URL: https://github.com/apache/airflow/pull/21983#discussion_r819300434



##########
File path: tests/cli/commands/test_connection_command.py
##########
@@ -34,13 +32,11 @@
 from tests.test_utils.db import clear_db_connections
 
 
-class TestCliGetConnection(unittest.TestCase):
-    def setUp(self):
-        self.parser = cli_parser.get_parser()
-        clear_db_connections()
+class TestCliGetConnection:
+    parser = cli_parser.get_parser()
 
-    def tearDown(self):
-        clear_db_connections()
+    def setup_method(self):
+        clear_db_connections(add_default_connections_back=True)

Review comment:
       like
   ```




-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] dstandish commented on a change in pull request #21983: Simplify tests for CLI connections commands

Posted by GitBox <gi...@apache.org>.
dstandish commented on a change in pull request #21983:
URL: https://github.com/apache/airflow/pull/21983#discussion_r819302242



##########
File path: tests/cli/commands/test_connection_command.py
##########
@@ -34,13 +32,11 @@
 from tests.test_utils.db import clear_db_connections
 
 
-class TestCliGetConnection(unittest.TestCase):
-    def setUp(self):
-        self.parser = cli_parser.get_parser()
-        clear_db_connections()
+class TestCliGetConnection:
+    parser = cli_parser.get_parser()
 
-    def tearDown(self):
-        clear_db_connections()
+    def setup_method(self):
+        clear_db_connections(add_default_connections_back=True)

Review comment:
       actually 6 :) 




-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] dstandish commented on a change in pull request #21983: Simplify tests for CLI connections commands

Posted by GitBox <gi...@apache.org>.
dstandish commented on a change in pull request #21983:
URL: https://github.com/apache/airflow/pull/21983#discussion_r819300505



##########
File path: tests/cli/commands/test_connection_command.py
##########
@@ -34,13 +32,11 @@
 from tests.test_utils.db import clear_db_connections
 
 
-class TestCliGetConnection(unittest.TestCase):
-    def setUp(self):
-        self.parser = cli_parser.get_parser()
-        clear_db_connections()
+class TestCliGetConnection:
+    parser = cli_parser.get_parser()
 
-    def tearDown(self):
-        clear_db_connections()
+    def setup_method(self):
+        clear_db_connections(add_default_connections_back=True)

Review comment:
       like
   ```
   @pytest.fixture(scope='class', autouse=True)
   def clear_connections():
       yield
       clear_db_connections(add_default_connections_back=False)
   
   ```




-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] dstandish commented on a change in pull request #21983: Simplify tests for CLI connections commands

Posted by GitBox <gi...@apache.org>.
dstandish commented on a change in pull request #21983:
URL: https://github.com/apache/airflow/pull/21983#discussion_r819300926



##########
File path: tests/cli/commands/test_connection_command.py
##########
@@ -34,13 +32,11 @@
 from tests.test_utils.db import clear_db_connections
 
 
-class TestCliGetConnection(unittest.TestCase):
-    def setUp(self):
-        self.parser = cli_parser.get_parser()
-        clear_db_connections()
+class TestCliGetConnection:
+    parser = cli_parser.get_parser()
 
-    def tearDown(self):
-        clear_db_connections()
+    def setup_method(self):
+        clear_db_connections(add_default_connections_back=True)

Review comment:
       done




-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] dstandish merged pull request #21983: Simplify tests for CLI connections commands

Posted by GitBox <gi...@apache.org>.
dstandish merged pull request #21983:
URL: https://github.com/apache/airflow/pull/21983


   


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] uranusjr commented on a change in pull request #21983: Simplify tests for CLI connections commands

Posted by GitBox <gi...@apache.org>.
uranusjr commented on a change in pull request #21983:
URL: https://github.com/apache/airflow/pull/21983#discussion_r819298042



##########
File path: tests/cli/commands/test_connection_command.py
##########
@@ -34,13 +32,11 @@
 from tests.test_utils.db import clear_db_connections
 
 
-class TestCliGetConnection(unittest.TestCase):
-    def setUp(self):
-        self.parser = cli_parser.get_parser()
-        clear_db_connections()
+class TestCliGetConnection:
+    parser = cli_parser.get_parser()
 
-    def tearDown(self):
-        clear_db_connections()
+    def setup_method(self):
+        clear_db_connections(add_default_connections_back=True)

Review comment:
       I think we should do this after the test to clean up properly. Maybe a `setup_class` and a `teardown_method` so we ensure a clean slate both before and after each test.




-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] github-actions[bot] commented on pull request #21983: Simplify tests for CLI connections commands

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on pull request #21983:
URL: https://github.com/apache/airflow/pull/21983#issuecomment-1059401450


   The PR is likely OK to be merged with just subset of tests for default Python and Database versions without running the full matrix of tests, because it does not modify the core of Airflow. If the committers decide that the full tests matrix is needed, they will add the label 'full tests needed'. Then you should rebase to the latest main or amend the last commit of the PR, and push it with --force-with-lease.


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org