@@ -34,7 +34,7 @@ def unit(session):
3434 """Run the unit test suite."""
3535
3636 session .install (
37- "pytest" , "pytest-xdist" , "pyfakefs" ,
37+ "coverage" , "pytest-cov" , " pytest" , "pytest-xdist" , "pyfakefs" ,
3838 )
3939 session .install ("-e" , "." )
4040
@@ -45,6 +45,10 @@ def unit(session):
4545 or [
4646 "-vv" ,
4747 "-n=auto" ,
48+ "--cov=gapic" ,
49+ "--cov-config=.coveragerc" ,
50+ "--cov-report=term" ,
51+ "--cov-fail-under=100" ,
4852 path .join ("tests" , "unit" ),
4953 ]
5054 ),
@@ -115,7 +119,7 @@ def showcase_library(
115119 )
116120
117121 # Install the library.
118- session .install (tmp_dir )
122+ session .install ("-e" , tmp_dir )
119123
120124 yield tmp_dir
121125
@@ -181,7 +185,9 @@ def showcase_mtls_alternative_templates(session):
181185
182186def run_showcase_unit_tests (session , fail_under = 100 ):
183187 session .install (
188+ "coverage" ,
184189 "pytest" ,
190+ "pytest-cov" ,
185191 "pytest-xdist" ,
186192 "asyncmock" ,
187193 "pytest-asyncio" ,
@@ -192,6 +198,9 @@ def run_showcase_unit_tests(session, fail_under=100):
192198 "py.test" ,
193199 "-n=auto" ,
194200 "--quiet" ,
201+ "--cov=google" ,
202+ "--cov-append" ,
203+ f"--cov-fail-under={ str (fail_under )} " ,
195204 * (session .posargs or [path .join ("tests" , "unit" )]),
196205 )
197206
@@ -217,11 +226,11 @@ def showcase_unit(
217226 # google-auth is a transitive dependency so it isn't in the
218227 # lower bound constraints file produced above.
219228 session .install ("google-auth==1.21.1" )
220- run_showcase_unit_tests (session )
229+ run_showcase_unit_tests (session , fail_under = 0 )
221230
222231 # 2. Run the tests again with latest version of dependencies
223232 session .install ("." , "--upgrade" , "--force-reinstall" )
224- run_showcase_unit_tests (session )
233+ run_showcase_unit_tests (session , fail_under = 100 )
225234
226235
227236@nox .session (python = ["3.7" , "3.8" , "3.9" ])
@@ -248,11 +257,11 @@ def showcase_unit_add_iam_methods(session):
248257 # google-auth is a transitive dependency so it isn't in the
249258 # lower bound constraints file produced above.
250259 session .install ("google-auth==1.21.1" )
251- run_showcase_unit_tests (session )
260+ run_showcase_unit_tests (session , fail_under = 0 )
252261
253262 # 2. Run the tests again with latest version of dependencies
254263 session .install ("." , "--upgrade" , "--force-reinstall" )
255- run_showcase_unit_tests (session )
264+ run_showcase_unit_tests (session , fail_under = 100 )
256265
257266
258267@nox .session (python = "3.8" )
0 commit comments