@@ -40,7 +40,7 @@ def _list_files(folder, pattern):
4040
4141def _collect_dirs (
4242 start_dir ,
43- blacklist = set (['conftest.py' , 'nox .py' , 'lib' , 'third_party' ]),
43+ blacklist = set (['conftest.py' , 'noxfile .py' , 'lib' , 'third_party' ]),
4444 suffix = '_test.py' ,
4545 recurse_further = False ):
4646 """Recursively collects a list of dirs that contain a file matching the
@@ -52,8 +52,10 @@ def _collect_dirs(
5252 # Collect all the directories that have tests in them.
5353 for parent , subdirs , files in os .walk (start_dir ):
5454 if './.' in parent :
55- continue # Skip top-level dotfiles
56- elif any (f for f in files if f .endswith (suffix ) and f not in blacklist ):
55+ continue # Skip top-level dotfiles
56+ elif any (
57+ f for f in files if f .endswith (suffix ) and f not in blacklist
58+ ):
5759 # Don't recurse further for tests, since py.test will do that.
5860 if not recurse_further :
5961 del subdirs [:]
@@ -147,13 +149,17 @@ def _setup_appengine_sdk(session):
147149 '--show-source' , '--builtin' , 'gettext' , '--max-complexity' , '20' ,
148150 '--import-order-style' , 'google' ,
149151 '--exclude' , '.nox,.cache,env,lib,generated_pb2,*_pb2.py,*_pb2_grpc.py' ,
150- '--ignore=E121,E123,E126,E226,E24,E704,W503,W504,I202' ,
152+ '--ignore=E121,E123,E126,E226,E24,E704,W503,W504,I100,I201, I202' ,
151153]
152154
153155
154156# Collect sample directories.
155157ALL_TESTED_SAMPLES = sorted (list (_collect_dirs ('.' )))
156- ALL_SAMPLE_DIRECTORIES = sorted (list (_collect_dirs ('.' , suffix = '.py' , recurse_further = True )))
158+ ALL_SAMPLE_DIRECTORIES = sorted (list (_collect_dirs (
159+ '.' ,
160+ suffix = '.py' ,
161+ recurse_further = True
162+ )))
157163GAE_STANDARD_SAMPLES = [
158164 sample for sample in ALL_TESTED_SAMPLES
159165 if sample .startswith ('./appengine/standard/' )]
@@ -162,9 +168,11 @@ def _setup_appengine_sdk(session):
162168 sample for sample in ALL_TESTED_SAMPLES
163169 if (sample .startswith ('./appengine/standard_python37' )
164170 or sample .startswith ('./functions/' ))]
165- NON_GAE_STANDARD_SAMPLES_PY2 = sorted (
166- list ((set (ALL_TESTED_SAMPLES ) - set (GAE_STANDARD_SAMPLES )) -
167- set (PY3_ONLY_SAMPLES )))
171+ NON_GAE_STANDARD_SAMPLES_PY2 = sorted (list ((
172+ set (ALL_TESTED_SAMPLES ) -
173+ set (GAE_STANDARD_SAMPLES )) -
174+ set (PY3_ONLY_SAMPLES )
175+ ))
168176NON_GAE_STANDARD_SAMPLES_PY3 = sorted (
169177 list (set (ALL_TESTED_SAMPLES ) - set (PY2_ONLY_SAMPLES )))
170178
@@ -193,7 +201,7 @@ def _session_tests(session, sample, post_install=None):
193201
194202 session .chdir (sample )
195203
196- if os .path .exists (os . path . join ( sample , 'requirements.txt' ) ):
204+ if os .path .exists ('requirements.txt' ):
197205 session .install ('-r' , 'requirements.txt' )
198206
199207 if post_install :
@@ -208,10 +216,10 @@ def _session_tests(session, sample, post_install=None):
208216 success_codes = [0 , 5 ])
209217
210218
219+ @nox .session (python = '2.7' )
211220@nox .parametrize ('sample' , GAE_STANDARD_SAMPLES )
212- def session_gae (session , sample ):
221+ def gae (session , sample ):
213222 """Runs py.test for an App Engine standard sample."""
214- session .interpreter = 'python2.7'
215223
216224 # Create a lib directory if needed, otherwise the App Engine vendor library
217225 # will complain.
@@ -221,22 +229,23 @@ def session_gae(session, sample):
221229 _session_tests (session , sample , _setup_appengine_sdk )
222230
223231
232+ @nox .session (python = '2.7' )
224233@nox .parametrize ('sample' , NON_GAE_STANDARD_SAMPLES_PY2 )
225- def session_py27 (session , sample ):
234+ def py27 (session , sample ):
226235 """Runs py.test for a sample using Python 2.7"""
227- session .interpreter = 'python2.7'
228236 _session_tests (session , sample )
229237
230238
239+ @nox .session (python = '3.6' )
231240@nox .parametrize ('sample' , NON_GAE_STANDARD_SAMPLES_PY3 )
232- def session_py36 (session , sample ):
241+ def py36 (session , sample ):
233242 """Runs py.test for a sample using Python 3.6"""
234- session .interpreter = 'python3.6'
235243 _session_tests (session , sample )
236244
237245
246+ @nox .session
238247@nox .parametrize ('sample' , ALL_SAMPLE_DIRECTORIES )
239- def session_lint (session , sample ):
248+ def lint (session , sample ):
240249 """Runs flake8 on the sample."""
241250 session .install ('flake8' , 'flake8-import-order' )
242251
@@ -253,10 +262,9 @@ def session_lint(session, sample):
253262# Utility sessions
254263#
255264
256-
257- def session_missing_tests (session ):
265+ @ nox . session
266+ def missing_tests (session ):
258267 """Lists all sample directories that do not have tests."""
259- session .virtualenv = False
260268 print ('The following samples do not have tests:' )
261269 for sample in set (ALL_SAMPLE_DIRECTORIES ) - set (ALL_TESTED_SAMPLES ):
262270 print ('* {}' .format (sample ))
@@ -266,8 +274,9 @@ def session_missing_tests(session):
266274 list (_collect_dirs ('.' , suffix = '.rst.in' )))
267275
268276
277+ @nox .session
269278@nox .parametrize ('sample' , SAMPLES_WITH_GENERATED_READMES )
270- def session_readmegen (session , sample ):
279+ def readmegen (session , sample ):
271280 """(Re-)generates the readme for a sample."""
272281 session .install ('jinja2' , 'pyyaml' )
273282
@@ -278,7 +287,8 @@ def session_readmegen(session, sample):
278287 session .run ('python' , 'scripts/readme-gen/readme_gen.py' , in_file )
279288
280289
281- def session_check_requirements (session ):
290+ @nox .session
291+ def check_requirements (session ):
282292 """Checks for out of date requirements and optionally updates them.
283293
284294 This is intentionally not parametric, as it's desired to never have two
0 commit comments