Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
4 changes: 1 addition & 3 deletions template/python3-flask-debian/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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/

Expand Down
2 changes: 1 addition & 1 deletion template/python3-flask-debian/function/handler_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
3 changes: 1 addition & 2 deletions template/python3-flask/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion template/python3-flask/function/handler_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
5 changes: 1 addition & 4 deletions template/python3-http-debian/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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/

Expand Down
2 changes: 1 addition & 1 deletion template/python3-http-debian/function/handler_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
3 changes: 1 addition & 2 deletions template/python3-http/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion template/python3-http/function/handler_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
Loading