From 5d1f0ecae7f7edeb5f6d7ee0e30d72180216a5d1 Mon Sep 17 00:00:00 2001 From: Dmitry Erlikh Date: Thu, 28 Oct 2021 16:52:39 +0200 Subject: [PATCH] Run test in docker (#6132) * Add make targets for testing with specific version in Docker * Update docs * add CHANGES file * fix spelling --- CHANGES/6131.misc | 1 + Makefile | 24 ++++++++++++++++++++++++ docs/contributing.rst | 12 ++++++++++++ tools/testing/Dockerfile | 15 +++++++++++++++ tools/testing/Dockerfile.dockerignore | 4 ++++ tools/testing/entrypoint.sh | 5 +++++ 6 files changed, 61 insertions(+) create mode 100644 CHANGES/6131.misc create mode 100644 tools/testing/Dockerfile create mode 100644 tools/testing/Dockerfile.dockerignore create mode 100644 tools/testing/entrypoint.sh diff --git a/CHANGES/6131.misc b/CHANGES/6131.misc new file mode 100644 index 00000000000..907a6d55af3 --- /dev/null +++ b/CHANGES/6131.misc @@ -0,0 +1 @@ +Add test targets to Makefile for different versions of Python diff --git a/Makefile b/Makefile index 81b8a0325c3..3edcdddd273 100644 --- a/Makefile +++ b/Makefile @@ -104,6 +104,30 @@ cov-dev: .develop @pytest --cov-report=html @echo "xdg-open file://`pwd`/htmlcov/index.html" + +define run_tests_in_docker + DOCKER_BUILDKIT=1 docker build --build-arg PYTHON_VERSION=$(1) --build-arg AIOHTTP_NO_EXTENSIONS=$(2) -t "aiohttp-test-$(1)-$(2)" -f tools/testing/Dockerfile . + docker run --rm -ti -v `pwd`:/src -w /src "aiohttp-test-$(1)-$(2)" $(TEST_SPEC) +endef + +.PHONY: test-3.7-no-extensions test-3.7 test-3.8-no-extensions test-3.8 test-3.9-no-extensions test-3.9 test-3.10-no-extensions test-3.10 +test-3.7-no-extensions: + $(call run_tests_in_docker,3.7,y) +test-3.7: + $(call run_tests_in_docker,3.7,n) +test-3.8-no-extensions: + $(call run_tests_in_docker,3.8,y) +test-3.8: + $(call run_tests_in_docker,3.8,n) +test-3.9-no-extensions: + $(call run_tests_in_docker,3.9,y) +test-3.9: + $(call run_tests_in_docker,3.9,n) +test-3.10-no-extensions: + $(call run_tests_in_docker,3.10,y) +test-3.10: + $(call run_tests_in_docker,3.10,n) + .PHONY: clean clean: @rm -rf `find . -name __pycache__` diff --git a/docs/contributing.rst b/docs/contributing.rst index 77fe4062212..5abfd0e0cc1 100644 --- a/docs/contributing.rst +++ b/docs/contributing.rst @@ -141,6 +141,18 @@ Please take a look on the produced output. Any extra texts (print statements and so on) should be removed. +.. note:: + + If you see that CI build is failing on a specific Python version and + you don't have this version on your computer, you can use the helper to + run it (only if you have docker):: + + make test-[-no-extensions] + + For example, if you want to run tests for python3.7 + without extensions, you can run this command:: + + make test-3.7-no-extensions Tests coverage -------------- diff --git a/tools/testing/Dockerfile b/tools/testing/Dockerfile new file mode 100644 index 00000000000..c3588e5affc --- /dev/null +++ b/tools/testing/Dockerfile @@ -0,0 +1,15 @@ +ARG PYTHON_VERSION +FROM python:$PYTHON_VERSION + +ARG AIOHTTP_NO_EXTENSIONS +ENV AIOHTTP_NO_EXTENSIONS=$AIOHTTP_NO_EXTENSIONS + +WORKDIR /deps +ADD ./requirements ./requirements +ADD Makefile . +RUN make install + +ADD ./tools/testing/entrypoint.sh / + +WORKDIR /src +ENTRYPOINT ["/bin/bash", "/entrypoint.sh"] diff --git a/tools/testing/Dockerfile.dockerignore b/tools/testing/Dockerfile.dockerignore new file mode 100644 index 00000000000..c8139993500 --- /dev/null +++ b/tools/testing/Dockerfile.dockerignore @@ -0,0 +1,4 @@ +* +!/requirements +!/Makefile +!/tools/testing/entrypoint.sh diff --git a/tools/testing/entrypoint.sh b/tools/testing/entrypoint.sh new file mode 100644 index 00000000000..e2a763db2e1 --- /dev/null +++ b/tools/testing/entrypoint.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +[[ "$AIOHTTP_NO_EXTENSIONS" != "y" ]] && make cythonize + +python -m pytest -qx --no-cov $1