Skip to content

Commit

Permalink
[AIRFLOW-6216] Allow pytests to be run without "tests" (#6770)
Browse files Browse the repository at this point in the history
With this change you should be able to simply run `pytest` to run all the tests in the main airflow directory.

This consist of two changes:

* moving pytest.ini to the main airflow directory
* skipping collecting kubernetes tests when ENV != kubernetes

(cherry picked from commit 239d51e)
  • Loading branch information
potiuk authored and kaxil committed Dec 12, 2019
1 parent 6336d36 commit 1efc9e2
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 12 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
!.coveragerc
!.rat-excludes
!.flake8
!pytest.ini
!LICENSE
!MANIFEST.in
!NOTICE
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ COPY docs/ ${AIRFLOW_SOURCES}/docs/
COPY tests/ ${AIRFLOW_SOURCES}/tests/
COPY airflow/ ${AIRFLOW_SOURCES}/airflow/
COPY .coveragerc .rat-excludes .flake8 LICENSE MANIFEST.in NOTICE CHANGELOG.txt \
.github \
.github pytest.ini \
setup.cfg setup.py \
${AIRFLOW_SOURCES}/

Expand Down
2 changes: 2 additions & 0 deletions tests/pytest.ini → pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ addopts =
--ignore=tests/dags/test_impersonation_subdag.py
--ignore=tests/dags/test_subdag.py
norecursedirs =
.eggs
airflow
tests/dags
tests/dags_with_system_exit
tests/test_utils
Expand Down
11 changes: 2 additions & 9 deletions scripts/ci/_utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ function print_info() {
declare -a AIRFLOW_CONTAINER_EXTRA_DOCKER_FLAGS
if [[ ${AIRFLOW_MOUNT_SOURCE_DIR_FOR_STATIC_CHECKS} == "true" ]]; then
print_info
print_info "Mount whole sourcce directory for static checks"
print_info "Mount whole airflow source directory for static checks (make sure all files are in container)"
print_info
AIRFLOW_CONTAINER_EXTRA_DOCKER_FLAGS=( \
"-v" "${AIRFLOW_SOURCES}:/opt/airflow" \
Expand All @@ -104,6 +104,7 @@ elif [[ ${AIRFLOW_MOUNT_HOST_VOLUMES_FOR_STATIC_CHECKS} == "true" ]]; then
"-v" "${AIRFLOW_SOURCES}/tmp:/opt/airflow/tmp:cached" \
"-v" "${AIRFLOW_SOURCES}/tests:/opt/airflow/tests:cached" \
"-v" "${AIRFLOW_SOURCES}/.flake8:/opt/airflow/.flake8:cached" \
"-v" "${AIRFLOW_SOURCES}/pytest.ini:/opt/airflow/pytest.ini:cached" \
"-v" "${AIRFLOW_SOURCES}/setup.cfg:/opt/airflow/setup.cfg:cached" \
"-v" "${AIRFLOW_SOURCES}/setup.py:/opt/airflow/setup.py:cached" \
"-v" "${AIRFLOW_SOURCES}/.rat-excludes:/opt/airflow/.rat-excludes:cached" \
Expand Down Expand Up @@ -802,14 +803,6 @@ function build_image_on_ci() {
fi
elif [[ ${TRAVIS_JOB_NAME} == "Static"* ]]; then
rebuild_ci_image_if_needed
elif [[ ${TRAVIS_JOB_NAME} == "Pylint"* ]]; then
rebuild_ci_slim_image_if_needed
match_files_regexp '.*\.py'
if [[ ${FILE_MATCHES} == "true" || ${TRAVIS_PULL_REQUEST:=} == "false" ]]; then
rebuild_ci_image_if_needed
else
touch "${BUILD_CACHE_DIR}"/.skip_tests
fi
elif [[ ${TRAVIS_JOB_NAME} == "Build documentation"* ]]; then
rebuild_ci_image_if_needed
else
Expand Down
1 change: 1 addition & 0 deletions scripts/ci/docker-compose-local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ services:
- ../../.bash_aliases:/root/.bash_aliases:cached
- ../../.inputrc:/root/.inputrc:cached
- ../../.flake8:/opt/airflow/.flake8:cached
- ../../pytest.ini:/opt/airflow/pytest.ini:cached
- ../../.rat-excludes:/opt/airflow/.rat-excludes:cached
- ../../logs:/root/airflow/logs:cached
- ../../tmp:/opt/airflow/tmp:cached
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/kubernetes/test_kubernetes_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
try:
check_call(["/usr/local/bin/kubectl", "get", "pods"])
except Exception as e: # pylint: disable=broad-except
if os.environ.get('KUBERNETES_VERSION'):
if os.environ.get('KUBERNETES_VERSION') and os.environ.get('ENV', 'kubernetes') == 'kubernetes':
raise e
else:
raise unittest.SkipTest(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
try:
check_call(["/usr/local/bin/kubectl", "get", "pods"])
except Exception as e: # pylint: disable=broad-except
if os.environ.get('KUBERNETES_VERSION'):
if os.environ.get('KUBERNETES_VERSION') and os.environ.get('ENV', 'kubernetes') == 'kubernetes':
raise e
else:
raise unittest.SkipTest(
Expand Down

0 comments on commit 1efc9e2

Please sign in to comment.