-
Hello, As I'm starting to contribute in the Airflow codebase I was wondering if you guys would be open to add following 2 testing libraries in Airflow. Having spent over 20 years writing Java code and transitioning to Python development in the past three years, we all know the importance of not only writing clean code but also ensuring its thoroughly tested – a principle we're all familiar with, I'm sure. In my previous Java projects, I relied on two libraries that are also available in Python: One might question the need for introducing two additional dependencies when Airflow already provides sufficient tools for testing. However, the advantage of these libraries lies in their ability to facilitate writing mocking statements and assertions in a fluent manner, thereby enhancing readability. For instance, if you wish to mock a DAG and its get_doc_md function based on specific parameters, you could achieve this succinctly as follows: from airflow.exceptions import AirflowDagInconsistent
from airflow.models import DAG
from mockito import eq, when, mock, ANY
dag = mock(spec=DAG)
when(dag).get_doc_md(ANY).thenReturn("Returns generic Markdown contents for any parameter")
when(dag).get_doc_md(matches("test")).thenReturn("Returns specific Markdown contents when the parameter contains 'test'")
when(dag).validate().thenRaise(AirflowDagInconsistent) Similarly, assertpy offers a more intuitive alternative to traditional assert statements. By leveraging its fluent API, you can chain assertions for improved clarity: from assertpy import assert_that
assert_that(actual).is_not_none().is_equal_to("Returns specific Markdown contents when the parameter contains 'test'")
assert_that([1, 2, 3]).is_type_of(list).contains_only(1, 2, 3) With assertpy, it's evident what you're asserting, as you first provide the actual value to be tested and then chain the desired assertions. There a are more examples shown on their website. This proposal is intended to enhance testing capabilities within Airflow. I'm keen to hear your thoughts on this matter. Kind regards, |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
I would recommend to open a discussion into the Dev List, see join community. Not all regular contributors/maintainers/PMC looking into the Github Discussions. Below only my personal thoughts, and should not be consider as "no we do not need it" |
Beta Was this translation helpful? Give feedback.
I would recommend to open a discussion into the Dev List, see join community. Not all regular contributors/maintainers/PMC looking into the Github Discussions.
Below only my personal thoughts, and should not be consider as "no we do not need it"
unittest
projects users