Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AIRFLOW-7000] Allow passing in env var JSON dict in task_test #7639

Merged
merged 1 commit into from
Mar 18, 2020

Conversation

KevinYang21
Copy link
Member

@KevinYang21 KevinYang21 commented Mar 7, 2020


Issue link: AIRFLOW-7000

  1. Allow batch passing in env var through JSON dict
  2. Set AIRFLOW_TEST_MODE for all airflow test executions

Make sure to mark the boxes below before creating PR: [x]

  • Description above provides context of the change
  • Commit message/PR title starts with [AIRFLOW-NNNN]. AIRFLOW-NNNN = JIRA ID*
  • Unit tests coverage for changes (not needed for documentation changes)
  • Commits follow "How to write a good git commit message"
  • Relevant documentation is updated including usage instructions.
  • I will engage committers as explained in Contribution Workflow Example.

* For document-only changes commit message can start with [AIRFLOW-XXXX].


In case of fundamental code change, Airflow Improvement Proposal (AIP) is needed.
In case of a new dependency, check compliance with the ASF 3rd Party License Policy.
In case of backwards incompatible changes please leave a note in UPDATING.md.
Read the Pull Request Guidelines for more information.

@KevinYang21 KevinYang21 force-pushed the kevin_yang_env_params branch 5 times, most recently from 8613b17 to 0c0627f Compare March 9, 2020 19:43
@KevinYang21 KevinYang21 marked this pull request as ready for review March 9, 2020 20:46
Copy link
Member

@kaxil kaxil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would be very useful 👍

@@ -320,6 +320,12 @@ def task_test(args, dag=None):
if not already_has_stream_handler:
logging.getLogger('airflow.task').propagate = True

env_vars = {'AIRFLOW_TEST_MODE'}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need AIRFLOW_TEST_MODE ?

Copy link
Member Author

@KevinYang21 KevinYang21 Mar 10, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is more to share AIRFLOW_TEST_MODE across all executions and provide a convinient default env var for people too lazy to specify the cli param. It's the most common one that we use( to differ dev env from prod env). Do you think it would be useful?

airflow/bin/cli.py Outdated Show resolved Hide resolved
@KevinYang21 KevinYang21 force-pushed the kevin_yang_env_params branch 2 times, most recently from b09b333 to f85ac05 Compare March 10, 2020 21:51
@kaxil
Copy link
Member

kaxil commented Mar 17, 2020

:( Travis is sad:

___________________ TestCliTasks.test_cli_test_with_env_vars ___________________
self = <tests.cli.commands.test_task_command.TestCliTasks testMethod=test_cli_test_with_env_vars>
    def test_cli_test_with_env_vars(self):
        with redirect_stdout(io.StringIO()) as stdout:
            task_command.task_test(self.parser.parse_args([
                'tasks', 'test', 'example_passing_params_via_test_command', 'env_var_test_task',
                '--env-vars', '{"foo":"bar"}', DEFAULT_DATE.isoformat()]))
>           self.assertIn('foo=bar', stdout.getvalue())
E           AssertionError: 'foo=bar' not found in "[\x1b[34m2020-03-17 05:28:39,212\x1b[0m] {\x1b[34mtest_task_view_type_check.py:\x1b[0m48} INFO\x1b[0m - class_instance type: \x1b[1m<class 'unusual_prefix_5d280a9b385120fec3c40cfe5be04e2f41b6b5e8_test_task_view_type_check.CallableClass'>\x1b[0m\x1b[0m\n"
tests/cli/commands/test_task_command.py:127: AssertionError

Co-authored-by: Haim Grosman <haim.grosman@airbnb.com>
@KevinYang21
Copy link
Member Author

@kaxil ya somehow the stdout capture in bash operator works only after the first test run... Reverted back to PythonOperator that other tests are using and we all green :D

@kaxil kaxil merged commit cc5376d into apache:master Mar 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants