Skip to content

Commit 1188716

Browse files
author
Doug Greiman
committed
Add nox support for running tests, lint, coverage, and requirements checking
1 parent 51c61aa commit 1188716

4 files changed

Lines changed: 57 additions & 1 deletion

File tree

.coveragerc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[run]
2+
branch = True
3+
4+
[report]
5+
exclude_lines =
6+
pragma: no cover

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
*.pyc
2+
.cache
3+
.coverage
24
.nox
35
/cloudbuild.yaml_local.sh
46
/cloudbuild_benchmark.yaml_local.sh

nox.py

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
import fnmatch
1616
import os
1717

18+
import nox
19+
1820

1921
def _list_files(folder, pattern):
2022
"""Lists all files below the given folder that match the pattern."""
@@ -24,7 +26,8 @@ def _list_files(folder, pattern):
2426
yield os.path.join(root, filename)
2527

2628

27-
def session_check_requirements(session):
29+
@nox.session
30+
def check_requirements(session):
2831
"""Checks for out of date requirements and optionally updates them."""
2932
session.install('gcp-devrel-py-tools')
3033

@@ -37,3 +40,44 @@ def session_check_requirements(session):
3740

3841
for reqfile in reqfiles:
3942
session.run('gcp-devrel-py-tools', command, reqfile)
43+
44+
45+
@nox.session
46+
def lint(session):
47+
session.install('flake8', 'flake8-import-order')
48+
session.run(
49+
'flake8',
50+
'--import-order-style=google',
51+
'scripts',
52+
'nox.py',
53+
)
54+
55+
56+
@nox.session
57+
@nox.parametrize('version', ['3.4', '3.5', '3.6'])
58+
def tests(session, version):
59+
session.interpreter = 'python' + version
60+
session.install('-r', 'scripts/requirements-test.txt')
61+
session.run(
62+
'py.test',
63+
'--ignore=scripts/testdata',
64+
'--cov=scripts',
65+
'--cov-append',
66+
'--cov-config=.coveragerc',
67+
'--cov-report=', # Report generated below
68+
'scripts',
69+
env={'PYTHONPATH': ''}
70+
)
71+
72+
73+
@nox.session
74+
def cover(session):
75+
"""Run the final coverage report.
76+
77+
This outputs the coverage report aggregating coverage from the unit
78+
test runs (not system test runs), and then erases coverage data.
79+
"""
80+
session.interpreter = 'python3.6'
81+
session.install('coverage', 'pytest-cov')
82+
session.run('coverage', 'report', '--show-missing', '--fail-under=97')
83+
session.run('coverage', 'erase')

scripts/requirements-test.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
flask
2+
pytest
3+
pytest-cov
4+
pyyaml

0 commit comments

Comments
 (0)