Skip to content
Permalink
Browse files
Move tests command in new breeze (#23445)
  • Loading branch information
joppevos committed May 6, 2022
1 parent 83784d9 commit 7ba4e35a9d1b65b4c1a318ba4abdf521f98421a2
Showing 7 changed files with 264 additions and 46 deletions.
@@ -477,11 +477,9 @@ Those are commands mostly used by contributors:
* Build documentation with ``breeze build-docs`` command
* Initialize local virtualenv with ``./scripts/tools/initialize_virtualenv.py`` command
* Run static checks with autocomplete support ``breeze static-checks`` command
* Run test specified with ``./breeze-legacy tests`` command
* Run test specified with ``breeze tests`` command
* Build CI docker image with ``breeze build-image`` command
* Cleanup breeze with ``breeze cleanup`` command
* Run static checks with autocomplete support ``breeze static-checks`` command
* Run test specified with ``./breeze-legacy tests`` command

Additional management tasks:

@@ -493,6 +491,11 @@ Tests
-----

* Run docker-compose tests with ``breeze docker-compose-tests`` command.
* Run test specified with ``breeze tests`` command.

.. image:: ./images/breeze/output-tests.svg
:width: 100%
:alt: Breeze tests

Kubernetes tests
----------------
@@ -168,19 +168,19 @@ to breeze.

.. code-block:: bash
./breeze-legacy tests tests/providers/http/hooks/test_http.py tests/core/test_core.py --db-reset -- --log-cli-level=DEBUG
breeze tests tests/providers/http/hooks/test_http.py tests/core/test_core.py --db-reset --log-cli-level=DEBUG
You can run the whole test suite without adding the test target:

.. code-block:: bash
./breeze-legacy tests --db-reset
breeze tests --db-reset
You can also specify individual tests or a group of tests:

.. code-block:: bash
./breeze-legacy tests --db-reset tests/core/test_core.py::TestCore
breeze tests --db-reset tests/core/test_core.py::TestCore
Running Tests of a specified type from the Host
@@ -15,29 +15,36 @@
# specific language governing permissions and limitations
# under the License.

import os
import sys
from typing import Tuple

import click

from airflow_breeze.build_image.prod.build_prod_params import BuildProdParams
from airflow_breeze.commands.common_options import (
option_db_reset,
option_dry_run,
option_github_repository,
option_image_name,
option_image_tag,
option_integration,
option_python,
option_verbose,
)
from airflow_breeze.commands.custom_param_types import BetterChoice
from airflow_breeze.commands.main import main
from airflow_breeze.global_constants import ALLOWED_TEST_TYPES
from airflow_breeze.shell.enter_shell import check_docker_is_running, check_docker_resources
from airflow_breeze.shell.shell_params import ShellParams
from airflow_breeze.utils.console import get_console
from airflow_breeze.utils.docker_command_utils import construct_env_variables_docker_compose_command
from airflow_breeze.utils.run_tests import run_docker_compose_tests
from airflow_breeze.utils.run_utils import run_command

TESTING_COMMANDS = {
"name": "Testing",
"commands": [
"docker-compose-tests",
],
"commands": ["docker-compose-tests", "tests"],
}

TESTING_PARAMETERS = {
@@ -51,6 +58,16 @@
],
}
],
"breeze tests": [
{
"name": "Basic flag for tests command",
"options": [
"--integration",
"--test-type",
"--db-reset",
],
}
],
}


@@ -91,3 +108,56 @@ def docker_compose_tests(
extra_pytest_args=extra_pytest_args,
)
sys.exit(return_code)


@main.command(
name='tests',
help="Run the specified unit test targets. Multiple targets may be specified separated by spaces.",
context_settings=dict(
ignore_unknown_options=True,
allow_extra_args=True,
),
)
@option_dry_run
@option_verbose
@option_integration
@click.argument('extra_pytest_args', nargs=-1, type=click.UNPROCESSED)
@click.option(
"-tt",
"--test-type",
help="Type of test to run.",
default="All",
type=BetterChoice(ALLOWED_TEST_TYPES),
)
@option_db_reset
def tests(
dry_run: bool,
verbose: bool,
integration: Tuple,
extra_pytest_args: Tuple,
test_type: str,
db_reset: bool,
):
os.environ["RUN_TESTS"] = "true"
if test_type:
os.environ["TEST_TYPE"] = test_type
if integration:
if "trino" in integration:
integration = integration + ("kerberos",)
os.environ["LIST_OF_INTEGRATION_TESTS_TO_RUN"] = ' '.join(list(integration))
if db_reset:
os.environ["DB_RESET"] = "true"

exec_shell_params = ShellParams(verbose=verbose, dry_run=dry_run)
env_variables = construct_env_variables_docker_compose_command(exec_shell_params)
check_docker_is_running(verbose)
check_docker_resources(exec_shell_params.airflow_image_name, verbose=verbose, dry_run=dry_run)

cmd = ['docker-compose', 'run', '--service-ports', '--rm', 'airflow']
cmd.extend(list(extra_pytest_args))
run_command(
cmd,
verbose=verbose,
dry_run=dry_run,
env=env_variables,
)
@@ -23,8 +23,10 @@
from airflow_breeze.utils.cache import read_from_cache_file
from airflow_breeze.utils.console import get_console
from airflow_breeze.utils.docker_command_utils import (
check_docker_compose_version,
check_docker_is_running,
check_docker_resources,
check_docker_version,
construct_env_variables_docker_compose_command,
)
from airflow_breeze.utils.rebuild_image_if_needed import rebuild_ci_image_if_needed
@@ -46,12 +48,9 @@ def enter_shell(**kwargs) -> Union[subprocess.CompletedProcess, subprocess.Calle
"""
verbose = kwargs['verbose']
dry_run = kwargs['dry_run']
if not check_docker_is_running(verbose):
get_console().print(
'[error]Docker is not running.[/]\n'
'[warning]Please make sure Docker is installed and running.[/]'
)
sys.exit(1)
check_docker_is_running(verbose)
check_docker_version(verbose)
check_docker_compose_version(verbose)
if read_from_cache_file('suppress_asciiart') is None:
get_console().print(ASCIIART, style=ASCIIART_STYLE)
if read_from_cache_file('suppress_cheatsheet') is None:
@@ -18,6 +18,7 @@
import os
import re
import subprocess
import sys
from random import randint
from typing import Dict, List, Tuple, Union

@@ -174,11 +175,10 @@ def compare_version(current_version: str, min_version: str) -> bool:
return version.parse(current_version) >= version.parse(min_version)


def check_docker_is_running(verbose: bool) -> bool:
def check_docker_is_running(verbose: bool):
"""
Checks if docker is running. Suppressed Dockers stdout and stderr output.
:param verbose: print commands when running
:return: False if docker is not running.
"""
response = run_command(
["docker", "info"],
@@ -190,8 +190,11 @@ def check_docker_is_running(verbose: bool) -> bool:
check=False,
)
if response.returncode != 0:
return False
return True
get_console().print(
'[error]Docker is not running.[/]\n'
'[warning]Please make sure Docker is installed and running.[/]'
)
sys.exit(1)


def check_docker_version(verbose: bool):
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 7ba4e35

Please sign in to comment.