Skip to main content

Create E2E test scripts for Airflow DAGs testing

Project description

airflow-e2e

This packages aims to set up the scripts to run Airflow DAGs E2E tests.

Installation

pip install airflow-e2e

Usage

Pre-requisites

Before generating and running the E2E test scripts, the following folders and files are required to be present in your repository:

  1. A folder that contains the Airflow DAGs under test
  2. A folder that contains the E2E test suite(s)

Optionally, we can have a requirements.txt file at the root of your repository, which contains all Python packages required by your Airflow scheduler and workers to perform the tasks under tests.

In addition, we can optionally have a requirements-dev.txt file at the root of your repository, which contains all the Python packages required by the test runner to run your E2E test suites.

Generating the test scripts

To generate the Airflow E2E test scripts, run the following command at the root of your repository:

Generating Airflow E2E test scripts without requirements.txt and requirements-dev.txt:

airflow-e2e --dags dags/ --tests tests/e2e

If you have packages to be installed in the Airflow services:

airflow-e2e --dags dags/ --tests tests/e2e --with-custom-airflow-packages

If you have packages to be installed in the test runner service:

airflow-e2e --dags dags/ --tests tests/e2e --with-custom-test-packages

If you would like to have a MongoDB service to be set up together:

airflow-e2e --dags dags/ --tests tests/e2e --with-mongo

This will generate a docker folder at the root of your repository, and it will contain the following files:

<root_of_repository>
 |- docker/
     |- airflow_connections_and_variables_seeder/
     |   |- connections.yml
     |   |- variables.json
     |- .envrc
     |- docker-compose.yml
     |- docker-compose-dev.yml
     |- docker-compose-extras.yml
     |- docker-compose-manual-testing.yml
     |- docker-compose-tests.yml

In addition, for your convenience, the following make commands are printed on the console, should you be interested to use them:

clean:
	source ./docker/.envrc && \
	docker-compose \
	-f ./docker/docker-compose.yml \
	-f ./docker/docker-compose-dev.yml \
	-f ./docker/docker-compose-tests.yml \
	-f ./docker/docker-compose-extras.yml \
	down --remove-orphans --volumes

dev: clean
	source ./docker/.envrc && \
	docker-compose \
	-f ./docker/docker-compose.yml \
	-f ./docker/docker-compose-dev.yml \
	-f ./docker/docker-compose-extras.yml \
	up -d

wait_for_airflow_web_to_be_healthy:
	until [ $$(docker inspect -f '{{.State.Health.Status}}' airflow-web) = "healthy" ] ; do \
		sleep 1 ; \
	done

seeded_dev: dev wait_for_airflow_web_to_be_healthy
	docker exec airflow-scheduler sh -c \
	"airflow connections import /tmp/seed/connections.yaml && airflow variables import /tmp/seed/variables.json"

e2e:
	source ./docker/.envrc && \
	docker-compose \
	-f ./docker/docker-compose.yml \
	-f ./docker/docker-compose-tests.yml \
	-f ./docker/docker-compose-extras.yml \
	up --exit-code-from test-runner

Setting up the E2E tests

A .envrc file is generated in the docker/ folder as well. Replace the values of the fields with the placeholder <SECRET_STRING_TO_BE_FILLED_IN> with actual values of your choice. Please remember to add the following to your source code versioning tool ignore file (.gitignore for Git, for example):

.envrc*

Even though we may be using dummy credentials for our tests, we should still be vigilant when it comes to committing secrets.

Running the E2E tests

To run the E2E tests, you can run the following command:

source ./docker/.envrc && \
  docker-compose \
  -f ./docker/docker-compose.yml \
  -f ./docker/docker-compose-tests.yml \
  up --exit-code-from test-runner

Or, if you have copied the convenient make command from before, you can run:

make e2e

License

GNU GENERAL PUBLIC LICENSE v3

Testing

To run the tests, run the following command at the root of the repository:

make test

Changelog

Refer to CHANGELOG.md

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

airflow-e2e-0.2.2.tar.gz (32.1 kB view details)

Uploaded Source

Built Distribution

airflow_e2e-0.2.2-py3-none-any.whl (57.0 kB view details)

Uploaded Python 3

File details

Details for the file airflow-e2e-0.2.2.tar.gz.

File metadata

  • Download URL: airflow-e2e-0.2.2.tar.gz
  • Upload date:
  • Size: 32.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.9

File hashes

Hashes for airflow-e2e-0.2.2.tar.gz
Algorithm Hash digest
SHA256 e59f7e0abf89fcddfa0cb2c24988e0f6b9ede00298ba423b4a4d023a65862df2
MD5 fb8ee101a62f99ea5f8c9d7746b39882
BLAKE2b-256 f77f0e049a5d5c46d655db26a73ee17e138a9bd81e28421c2a8f02e5adadbc94

See more details on using hashes here.

File details

Details for the file airflow_e2e-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: airflow_e2e-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 57.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.9

File hashes

Hashes for airflow_e2e-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 91c75a49c8a820c3a60382eb68ce6ed2821677e1cf0db479c26286d12cb8aaa0
MD5 4aa20bcf0fd633d303fcd3995417c3d9
BLAKE2b-256 1763884b3a1d9c786bcc56d4176c18f83a59edcabe4f2b538bde501ed61fedd6

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page