Skip to content

Commit fef5672

Browse files
LucasRoesleralexellis
authored andcommitted
Use tox to test the python3-flask template
**What** - Add a sample tox.ini file to the python3-flask. This configuration will run pytest and flake8 for the function handler. The default flake8 is very resticted, only erroring for undefined names and syntax errors. This allows us to lint and test the function during `faas-cli build`, which should simplify CI flows for users. Using `tox` allows th euser to completely customize the test flow without requiring any changes to the template. - Add same test for the echo handler - Include documentationthat describes how to disable Signed-off-by: Lucas Roesler <roesler.lucas@gmail.com>
1 parent b7057b6 commit fef5672

File tree

4 files changed

+55
-5
lines changed

4 files changed

+55
-5
lines changed

template/python3-flask/Dockerfile

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,14 @@ WORKDIR /home/app/function/
3434
COPY function/requirements.txt .
3535
RUN pip install --user -r requirements.txt
3636

37-
WORKDIR /home/app/
38-
3937
#install function code
4038
USER root
4139

42-
COPY function function
43-
RUN chown -R app:app ./
40+
COPY function/ .
41+
RUN chown -R app:app ../
42+
RUN tox -l == 0 && tox
43+
44+
WORKDIR /home/app/
4445

4546
#configure WSGI server and healthcheck
4647
USER app
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from .handler import handle
2+
3+
# Test your handler here
4+
# To disable testing, you need to update the
5+
# tox.ini file, in addition to deleting this file.
6+
7+
def test_handle():
8+
assert handle("input") == "input"
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.*

0 commit comments

Comments
 (0)