diff --git a/README.md b/README.md index fb8e96a..9fbbd92 100644 --- a/README.md +++ b/README.md @@ -385,17 +385,27 @@ def handle(req): ## Testing -The `python3` templates will run `pytest` using `tox` during the `faas-cli build`. There are several options for controlling this. +The `python3` templates support running `pytest` using `tox` during `faas-cli build`. Testing is disabled by default and must be explicitly enabled. -### Disabling testing -The template exposes the build arg `TEST_ENABLED`. You can completely disable testing during build by passing the following flag to the CLI +### Enabling testing +The template exposes the build arg `TEST_ENABLED`. You can enable testing during build by passing the following flag to the CLI ```sh ---build-arg 'TEST_ENABLED=false' +--build-arg 'TEST_ENABLED=true' ``` You can also set it permanently in your stack.yaml, see the [YAML reference in the docs](https://docs.openfaas.com/reference/yaml/#function-build-args-build-args). +```yaml +functions: + fn: + lang: python3-http + handler: ./fn + image: fn:latest + build_args: + TEST_ENABLED: "true" +``` + ### Changing the test configuration The template creates a default `tox.ini` file, modifying this file can completely control what happens during the test. You can change the test command, for example switching to `nose`. See the [tox docs](https://tox.readthedocs.io/en/latest/index.html) for more details and examples. diff --git a/template/python3-flask-debian/Dockerfile b/template/python3-flask-debian/Dockerfile index 4470f8b..a1bbde3 100644 --- a/template/python3-flask-debian/Dockerfile +++ b/template/python3-flask-debian/Dockerfile @@ -47,12 +47,10 @@ USER root COPY --chown=app:app function/ . -FROM build AS test ARG TEST_COMMAND=tox -ARG TEST_ENABLED=true +ARG TEST_ENABLED=false RUN [ "$TEST_ENABLED" = "false" ] && echo "skipping tests" || eval "$TEST_COMMAND" - FROM build AS ship WORKDIR /home/app/ diff --git a/template/python3-flask-debian/function/handler_test.py b/template/python3-flask-debian/function/handler_test.py index b07d5bf..c4bf4af 100644 --- a/template/python3-flask-debian/function/handler_test.py +++ b/template/python3-flask-debian/function/handler_test.py @@ -2,7 +2,7 @@ # Test your handler here -# To disable testing, you can set the build_arg `TEST_ENABLED=false` on the CLI or in your stack.yml +# To enable testing, you can set the build_arg `TEST_ENABLED=true` on the CLI or in your stack.yml # https://docs.openfaas.com/reference/yaml/#function-build-args-build-args def test_handle(): diff --git a/template/python3-flask/Dockerfile b/template/python3-flask/Dockerfile index 1c344a2..1c4f48e 100644 --- a/template/python3-flask/Dockerfile +++ b/template/python3-flask/Dockerfile @@ -45,9 +45,8 @@ USER root COPY --chown=app:app function/ . -FROM build AS test ARG TEST_COMMAND=tox -ARG TEST_ENABLED=true +ARG TEST_ENABLED=false RUN [ "$TEST_ENABLED" = "false" ] && echo "skipping tests" || eval "$TEST_COMMAND" FROM build AS ship diff --git a/template/python3-flask/function/handler_test.py b/template/python3-flask/function/handler_test.py index b07d5bf..c4bf4af 100644 --- a/template/python3-flask/function/handler_test.py +++ b/template/python3-flask/function/handler_test.py @@ -2,7 +2,7 @@ # Test your handler here -# To disable testing, you can set the build_arg `TEST_ENABLED=false` on the CLI or in your stack.yml +# To enable testing, you can set the build_arg `TEST_ENABLED=true` on the CLI or in your stack.yml # https://docs.openfaas.com/reference/yaml/#function-build-args-build-args def test_handle(): diff --git a/template/python3-http-debian/Dockerfile b/template/python3-http-debian/Dockerfile index 2ae4ea7..1e18bb7 100644 --- a/template/python3-http-debian/Dockerfile +++ b/template/python3-http-debian/Dockerfile @@ -42,13 +42,10 @@ RUN pip install --no-cache-dir --user -r requirements.txt USER root COPY --chown=app:app function/ . -FROM build AS test - ARG TEST_COMMAND=tox -ARG TEST_ENABLED=true +ARG TEST_ENABLED=false RUN [ "$TEST_ENABLED" = "false" ] && echo "skipping tests" || eval "$TEST_COMMAND" - FROM build AS ship WORKDIR /home/app/ diff --git a/template/python3-http-debian/function/handler_test.py b/template/python3-http-debian/function/handler_test.py index b07d5bf..c4bf4af 100644 --- a/template/python3-http-debian/function/handler_test.py +++ b/template/python3-http-debian/function/handler_test.py @@ -2,7 +2,7 @@ # Test your handler here -# To disable testing, you can set the build_arg `TEST_ENABLED=false` on the CLI or in your stack.yml +# To enable testing, you can set the build_arg `TEST_ENABLED=true` on the CLI or in your stack.yml # https://docs.openfaas.com/reference/yaml/#function-build-args-build-args def test_handle(): diff --git a/template/python3-http/Dockerfile b/template/python3-http/Dockerfile index a5d2d8d..4ea40d4 100644 --- a/template/python3-http/Dockerfile +++ b/template/python3-http/Dockerfile @@ -41,9 +41,8 @@ RUN pip install --no-cache-dir --user -r requirements.txt USER root COPY --chown=app:app function/ . -FROM build AS test ARG TEST_COMMAND=tox -ARG TEST_ENABLED=true +ARG TEST_ENABLED=false RUN [ "$TEST_ENABLED" = "false" ] && echo "skipping tests" || eval "$TEST_COMMAND" FROM build AS ship diff --git a/template/python3-http/function/handler_test.py b/template/python3-http/function/handler_test.py index b07d5bf..c4bf4af 100644 --- a/template/python3-http/function/handler_test.py +++ b/template/python3-http/function/handler_test.py @@ -2,7 +2,7 @@ # Test your handler here -# To disable testing, you can set the build_arg `TEST_ENABLED=false` on the CLI or in your stack.yml +# To enable testing, you can set the build_arg `TEST_ENABLED=true` on the CLI or in your stack.yml # https://docs.openfaas.com/reference/yaml/#function-build-args-build-args def test_handle():