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 2020/10/21 01:55:00 UTC

[GitHub] [airflow] ashb commented on a change in pull request #11694: Create pytest fixtures for testing Helm chart templates

ashb commented on a change in pull request #11694:
URL: https://github.com/apache/airflow/pull/11694#discussion_r508942109



##########
File path: chart/tests/conftest.py
##########
@@ -0,0 +1,97 @@
+# 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.
+
+import logging
+import os
+import subprocess
+from typing import Dict, List, Optional
+
+import pytest
+import yaml
+
+log = logging.getLogger(__name__)
+
+CHART_FOLDER = os.path.normpath(os.path.join(__file__, os.pardir, os.pardir))
+
+
+def run_cmd(cmd, **kwargs):
+    """
+    Helper method to run a command, and include any output in case of error.
+    """
+    try:
+        log.debug('Running %s', cmd)
+        return subprocess.check_output(
+            cmd,
+            stderr=subprocess.STDOUT,
+            **kwargs
+        )
+    except subprocess.CalledProcessError as e:
+        raise AssertionError(f'Command {cmd} failed with: {e.output.decode("utf-8")}')
+
+
+@pytest.fixture(scope="session", autouse=True)
+def initalize_chart():
+    """
+    Get the helm chart ready to install/render.
+
+    This is run for us automatically by pytest once per test-session
+    """
+    run_cmd(['helm', 'repo', 'add', 'stable', 'https://kubernetes-charts.storage.googleapis.com/'])
+    run_cmd(['helm', 'dep', 'update', CHART_FOLDER])
+
+
+@pytest.fixture
+def render_chart(request):

Review comment:
       Yeah, in not sure either. I was basically looking at what we have in the yaml files and modelling this off of that.
   
   I was thinking it's kind of nice to not have to specify the same file in every test function of a class as they will likely be testing the same files bit with different value inputs.




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

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