You have a test that’s parametrized but only one of the examples fails. While it seems you may have run into an edge case, you don’t have time to fix the code but need to get the test to stop failing. (And it goes without saying that you can’t remove that example either!) One way […]
Tag: pytest
Testing Task Dependencies In Your DAG
While I have been using a simpler version in the past, it is only recently that I wrapped my head around how to simplify the creation–and really the maintenance–of upstream & downstream task dependencies in a DAG. The way I had been doing it involved writing these massive tuples with the task names over & […]
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 […]