Skip to content

Commit ff80c6b

Browse files
authored
Merge pull request #2874 from jeff1evesque/feature-2697
#2697: Send '.coverage' docker output to coveralls
2 parents 7c7548c + 5bc395d commit ff80c6b

File tree

5 files changed

+51
-20
lines changed

5 files changed

+51
-20
lines changed

.coveragerc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[paths]
2+
source =
3+
.
4+
/var/machine-learning

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
!/test
2020
!/log/
2121
!*.dockerfile
22+
!.coveragerc
2223

2324
# Ignore and don't commit the following directories
2425
*.sass-cache/

.travis.yml

Lines changed: 37 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ before_install:
3535
- sudo /opt/puppetlabs/bin/puppet -V
3636

3737
## install packages for linting
38-
#
39-
# @trusty-backports, allows additional packages (i.e. shellcheck) to be installed
40-
#
41-
# Note: unit testing is performed within the docker container, which is
42-
# defined from the Dockerfile.
38+
##
39+
## @trusty-backports, allows additional packages (i.e. shellcheck) to be installed
40+
##
41+
## Note: unit testing is performed within the docker container, which is
42+
## defined from the Dockerfile.
4343
install:
4444
- sudo add-apt-repository "deb http://archive.ubuntu.com/ubuntu/ trusty-backports restricted main universe"
4545
- pip install flake8==2.5.4
@@ -60,21 +60,22 @@ install:
6060
- gem install yaml-lint -v 0.0.7
6161
- npm install -g dockerlint@0.2.0
6262
- pip install restructuredtext_lint==0.17.2
63+
- pip install python-coveralls==2.9.0
6364

6465
## implement linting / unit tests
65-
#
66-
# @puppet-lint, the following issue needs to be checked if it has been
67-
# resolved, so the '--no-ensure_first_param-check' abusive flag
68-
# implementation (below) can be removed:
69-
#
70-
# - https://github.com/rodjek/puppet-lint/issues/410
71-
#
72-
# @docker run:
73-
# -d, run container in background and print container ID
74-
# -t, allocate pseudo-tty instead of default tty to running container
75-
#
76-
# Note: unit testing is performed within the docker container, which is
77-
# defined from the Dockerfile.
66+
##
67+
## @puppet-lint, the following issue needs to be checked if it has been
68+
## resolved, so the '--no-ensure_first_param-check' abusive flag
69+
## implementation (below) can be removed:
70+
##
71+
## - https://github.com/rodjek/puppet-lint/issues/410
72+
##
73+
## @docker run:
74+
## -d, run container in background and print container ID
75+
## -t, allocate pseudo-tty instead of default tty to running container
76+
##
77+
## Note: unit testing is performed within the docker container, which is
78+
## defined from the Dockerfile.
7879
script:
7980
# lint codebase
8081
- flake8 .
@@ -113,10 +114,28 @@ script:
113114
- cat pytest.log
114115
- (! grep -qE '= FAILURES =|= ERRORS =|= no tests ran in 0.00 seconds =' pytest.log)
115116

117+
## acquire coverage results
118+
##
119+
## Note: more information regarding the '.coverage.docker' naming convention:
120+
##
121+
## https://github.com/pytest-dev/pytest-cov/issues/146#issuecomment-272971136
122+
##
123+
- docker cp webserver-pytest:/var/machine-learning/.coverage .coverage.docker
124+
116125
# check exit code: 'docker exec' will fail if the container has an exit code
117126
- docker exec -it webserver echo "'docker exec' only works on an active running container"
118127
- docker exec -it database echo "'docker exec' only works on an active running container"
119128
- docker exec -it redis echo "'docker exec' only works on an active running container"
120129

121130
# list all containers
122131
- docker ps -a
132+
133+
## post build: the following commands are run after a successful build.
134+
##
135+
## Note: more information regarding the coverage-coverall implementation:
136+
##
137+
## https://github.com/pytest-dev/pytest-cov/issues/146
138+
##
139+
after_success:
140+
- coverage combine
141+
- coveralls

app.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@
1818
# run unit test
1919
if len(sys.argv) > 1:
2020
if sys.argv[1] == 'test':
21-
pytest.main(['test/live_server'])
21+
pytest.main([
22+
'--cov', '.',
23+
'test/live_server'
24+
])
2225
elif sys.argv[1] == 'run':
2326
args = {
2427
'prefix': 'test',

default.dockerfile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@ ENV ENVIRONMENT_DIR $ROOT_PROJECT/puppet/environment/$ENVIRONMENT
99
RUN mkdir /var/machine-learning
1010
COPY . /var/machine-learning
1111

12-
## install git, and wget
12+
## install git, wget, pip
1313
#
1414
# Note: r10k requires 'git' installed
1515
RUN apt-get -y update
1616
RUN apt-get -y install git=1:1.9.1-1ubuntu0.3
1717
RUN apt-get -y install wget=1.15-1ubuntu1.14.04.2
18+
RUN apt-get -y install python-pip=1.5.4-1ubuntu4
1819

1920
## install puppet
2021
RUN wget https://apt.puppetlabs.com/puppetlabs-release-pc1-trusty.deb
@@ -26,6 +27,9 @@ RUN apt-get -y install puppet-agent
2627
RUN apt-get -y install rubygems-integration=1.5
2728
RUN gem install r10k -v 2.2.0
2829

30+
## install pytest-cov
31+
RUN pip install pytest-cov==2.4.0
32+
2933
## install puppet modules using puppetfile with r10k
3034
RUN mkdir -p $ENVIRONMENT_DIR/modules_contrib/
3135
RUN PUPPETFILE=$ENVIRONMENT_DIR/Puppetfile PUPPETFILE_DIR=$ENVIRONMENT_DIR/modules_contrib/ r10k puppetfile install

0 commit comments

Comments
 (0)