This is an automated email from the ASF dual-hosted git repository.

ash pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/master by this push:
     new 0b50e32  Speed up TestFlaskCli test (#14865)
0b50e32 is described below

commit 0b50e3228519138c9826bc8e98f0ab5dc40a268d
Author: Ash Berlin-Taylor <[email protected]>
AuthorDate: Thu Mar 18 09:52:28 2021 +0000

    Speed up TestFlaskCli test (#14865)
    
    Creating a new process and reloading all of the app is slow, so instead
    use the built-in `runpy` module to run the `flask` module in the same
    interpreter, taking advantage of the already-cached app.
    
    This one test was taking about 20s, now down to 3s (still slow, but much
    much faster)
---
 tests/www/test_app.py | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/tests/www/test_app.py b/tests/www/test_app.py
index a96ea2a..47b8f81 100644
--- a/tests/www/test_app.py
+++ b/tests/www/test_app.py
@@ -15,7 +15,8 @@
 # KIND, either express or implied.  See the License for the
 # specific language governing permissions and limitations
 # under the License.
-import subprocess
+import runpy
+import sys
 import unittest
 from datetime import timedelta
 from unittest import mock
@@ -241,9 +242,13 @@ class TestApp(unittest.TestCase):
         assert app.config['SESSION_COOKIE_SAMESITE'] == 'Lax'
 
 
-class TestFlaskCli(unittest.TestCase):
-    @dont_initialize_flask_app_submodules
-    def test_flask_cli_should_display_routes(self):
-        with mock.patch.dict("os.environ", 
FLASK_APP="airflow.www.app:create_app"):
-            output = subprocess.check_output(["flask", "routes"])
-            assert "/api/v1/version" in output.decode()
+class TestFlaskCli:
+    @dont_initialize_flask_app_submodules(skip_all_except=['init_appbuilder'])
+    def test_flask_cli_should_display_routes(self, capsys):
+        with mock.patch.dict("os.environ", 
FLASK_APP="airflow.www.app:cached_app"), mock.patch.object(
+            sys, 'argv', ['flask', 'routes']
+        ), pytest.raises(SystemExit):
+            runpy.run_module('flask', run_name='__main__')
+
+        output = capsys.readouterr()
+        assert "/login/" in output.out

Reply via email to