Tag: pytest

Marking Tests as “Happy” or “Sad” with pytest

I was watching the video of a talk on Advanced pytest from EuroPython 2019 where the presenter (also a pytest core developer) used some interesting decorators in his slides (actually his blog). Being rather familiar with @pytest.mark.parametrize(), it wasn’t entirely obvious at first what @pytest.mark.wip, @pytest.mark.happy, & @pytest.mark.sad were doing or functionality they provided. However, […]

Testing for logging Output from PythonOperator Functions

While generally my python functions called by a PythonOperator end with return True, sometimes I would like for them to emit some useful information (like a count of how many objects it finished working on, rows loaded into a table, etc.) to the airflow logs via logging. The problem is “How do you test that […]

Testing SqlSensor & dealing with str.startswith

This was one of those “Of course multiple values can be passed/checked!”-type situations. I’ve written a couple new DAGs which use SqlSensor, and I want to use my existing test, test_database_operators_have_sql(), to make sure that I am passing a SQL statement to the SqlSensor task. Here’s how the test originally looked testing for just the […]

Using pytest.fixture to Test Airflow Context

I’ve been wanting to figure out a way that will allow me to test tasks that reference Airflow context (via provide_context=True), such as BranchPythonOperator orPythonOperator. What I’ve come up with is a fixture that returns a dictionary. (In my example below, I perhaps went a little overboard with configuring it to return all of the […]