1313# limitations under the License.
1414
1515from __future__ import absolute_import
16+
1617import os
1718
1819import nox
1920
2021
22+ LOCAL_DEPS = (
23+ os .path .join ('..' , 'api_core' ),
24+ os .path .join ('..' , 'core' ),
25+ )
26+
27+
2128@nox .session
22- @nox .parametrize ('python_version' , ['2.7' , '3.4' , '3.5' , '3.6' ])
23- def unit_tests (session , python_version ):
24- """Run the unit test suite."""
29+ def default (session ):
30+ """Default unit test session.
31+
32+ This is intended to be run **without** an interpreter set, so
33+ that the current ``python`` (on the ``PATH``) or the version of
34+ Python corresponding to the ``nox`` binary the ``PATH`` can
35+ run the tests.
36+ """
37+ # Install all test dependencies, then install this package in-place.
38+ session .install ('mock' , 'pytest' , 'pytest-cov' , * LOCAL_DEPS )
39+ session .install ('-e' , '.' )
2540
26- session .interpreter = 'python{}' .format (python_version )
41+ # Run py.test against the unit tests.
42+ session .run (
43+ 'py.test' ,
44+ '--quiet' ,
45+ '--cov=google.cloud.container' ,
46+ '--cov=google.cloud.container_v1' ,
47+ '--cov=tests.unit' ,
48+ '--cov-append' ,
49+ '--cov-config=.coveragerc' ,
50+ '--cov-report=' ,
51+ os .path .join ('tests' , 'unit' ),
52+ * session .posargs
53+ )
2754
28- session .virtualenv_dirname = 'unit-' + python_version
2955
30- session .install ('pytest' )
31- session .install ('-e' , '.' )
56+ @nox .session
57+ @nox .parametrize ('py' , ['2.7' , '3.4' , '3.5' , '3.6' ])
58+ def unit (session , py ):
59+ """Run the unit test suite."""
3260
33- session .run ('py.test' , '--quiet' , os .path .join ('tests' , 'unit' ))
61+ session .interpreter = 'python{}' .format (py )
62+ session .virtualenv_dirname = 'unit-' + py
63+ default (session )
3464
3565
3666@nox .session
37- @nox .parametrize ('python_version ' , ['2.7' , '3.6' ])
38- def system_tests (session , python_version ):
67+ @nox .parametrize ('py ' , ['2.7' , '3.6' ])
68+ def system (session , py ):
3969 """Run the system test suite."""
4070
4171 # Sanity check: Only run system tests if the environment variable is set.
4272 if not os .environ .get ('GOOGLE_APPLICATION_CREDENTIALS' , '' ):
4373 session .skip ('Credentials must be set via environment variable.' )
4474
4575 # Run the system tests against latest Python 2 and Python 3 only.
46- session .interpreter = 'python{}' .format (python_version )
76+ session .interpreter = 'python{}' .format (py )
4777
4878 # Set the virtualenv dirname.
49- session .virtualenv_dirname = 'sys-' + python_version
79+ session .virtualenv_dirname = 'sys-' + py
5080
5181 # Install all test dependencies, then install this package into the
5282 # virtualenv's dist-packages.
@@ -65,3 +95,16 @@ def lint_setup_py(session):
6595 session .install ('docutils' , 'pygments' )
6696 session .run ('python' , 'setup.py' , 'check' , '--restructuredtext' ,
6797 '--strict' )
98+
99+
100+ @nox .session
101+ def cover (session ):
102+ """Run the final coverage report.
103+
104+ This outputs the coverage report aggregating coverage from the unit
105+ test runs (not system test runs), and then erases coverage data.
106+ """
107+ session .interpreter = 'python3.6'
108+ session .install ('coverage' , 'pytest-cov' )
109+ session .run ('coverage' , 'report' , '--show-missing' , '--fail-under=60' )
110+ session .run ('coverage' , 'erase' )
0 commit comments