Skip to content

Commit 91271bc

Browse files
LucasRoesleralexellis
authored andcommitted
Use a separate varaible for controlling tests
**What** - add TEST_ENABLED build-arg to control if the tests are run or not. Should be easier to document and debug in the future. - Copy the implementation to all of the python3 templates Signed-off-by: Lucas Roesler <roesler.lucas@gmail.com>
1 parent 19512d2 commit 91271bc

File tree

23 files changed

+309
-8
lines changed

23 files changed

+309
-8
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

template/python3-flask-armhf/Dockerfile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,15 @@ WORKDIR /home/app/
3535
USER root
3636
COPY function function
3737
RUN chown -R app:app ./
38+
39+
ARG TEST_COMMAND=tox
40+
ARG TEST_ENABLED=true
41+
RUN if [ "$TEST_ENABLED" == "false" ]; then \
42+
echo "skipping tests";\
43+
else \
44+
eval "$TEST_COMMAND"; \
45+
fi
46+
3847
USER app
3948

4049
ENV fprocess="python index.py"
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from .handler import handle
2+
3+
# Test your handler here
4+
5+
# To disable testing, you can set the build_arg `TEST_ENABLED=false` on the CLI or in your stack.yml
6+
# https://docs.openfaas.com/reference/yaml/#function-build-args-build-args
7+
8+
def test_handle():
9+
# assert handle("input") == "input"
10+
pass
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# If you would like to disable
2+
# automated testing during faas-cli build,
3+
4+
# Replace the content of this file with
5+
# [tox]
6+
# skipsdist = true
7+
8+
# You can also edit, remove, or add additional test steps
9+
# by editing, removing, or adding new testenv sections
10+
11+
12+
# find out more about tox: https://tox.readthedocs.io/en/latest/
13+
[tox]
14+
envlist = lint,test
15+
skipsdist = true
16+
17+
[testenv:test]
18+
deps =
19+
flask
20+
pytest
21+
-rrequirements.txt
22+
commands =
23+
# run unit tests with pytest
24+
# https://docs.pytest.org/en/stable/
25+
# configure by adding a pytest.ini to your handler
26+
pytest
27+
28+
[testenv:lint]
29+
deps =
30+
flake8
31+
commands =
32+
flake8 .
33+
34+
[flake8]
35+
count = true
36+
max-line-length = 127
37+
max-complexity = 10
38+
statistics = true
39+
# stop the build if there are Python syntax errors or undefined names
40+
select = E9,F63,F7,F82
41+
show-source = true
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
flask
22
waitress
3-
3+
tox==3.*

template/python3-flask-debian/Dockerfile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,14 @@ USER root
4242
COPY function function
4343
RUN chown -R app:app ./
4444

45+
ARG TEST_COMMAND=tox
46+
ARG TEST_ENABLED=true
47+
RUN if [ "$TEST_ENABLED" == "false" ]; then \
48+
echo "skipping tests";\
49+
else \
50+
eval "$TEST_COMMAND"; \
51+
fi
52+
4553
#configure WSGI server and healthcheck
4654
USER app
4755

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from .handler import handle
2+
3+
# Test your handler here
4+
5+
# To disable testing, you can set the build_arg `TEST_ENABLED=false` on the CLI or in your stack.yml
6+
# https://docs.openfaas.com/reference/yaml/#function-build-args-build-args
7+
8+
def test_handle():
9+
# assert handle("input") == "input"
10+
pass
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# If you would like to disable
2+
# automated testing during faas-cli build,
3+
4+
# Replace the content of this file with
5+
# [tox]
6+
# skipsdist = true
7+
8+
# You can also edit, remove, or add additional test steps
9+
# by editing, removing, or adding new testenv sections
10+
11+
12+
# find out more about tox: https://tox.readthedocs.io/en/latest/
13+
[tox]
14+
envlist = lint,test
15+
skipsdist = true
16+
17+
[testenv:test]
18+
deps =
19+
flask
20+
pytest
21+
-rrequirements.txt
22+
commands =
23+
# run unit tests with pytest
24+
# https://docs.pytest.org/en/stable/
25+
# configure by adding a pytest.ini to your handler
26+
pytest
27+
28+
[testenv:lint]
29+
deps =
30+
flake8
31+
commands =
32+
flake8 .
33+
34+
[flake8]
35+
count = true
36+
max-line-length = 127
37+
max-complexity = 10
38+
statistics = true
39+
# stop the build if there are Python syntax errors or undefined names
40+
select = E9,F63,F7,F82
41+
show-source = true
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
flask
22
waitress
3-
3+
tox==3.*

template/python3-flask/Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ COPY function/ .
4141
RUN chown -R app:app ../
4242

4343
ARG TEST_COMMAND=tox
44-
RUN if [ "x$TEST_COMMAND" = "xoff" ]; then \
44+
ARG TEST_ENABLED=true
45+
RUN if [ "$TEST_ENABLED" == "false" ]; then \
4546
echo "skipping tests";\
4647
else \
4748
eval "$TEST_COMMAND"; \

0 commit comments

Comments
 (0)