@@ -188,42 +188,52 @@ def _session_tests(
188
188
# check for presence of tests
189
189
test_list = glob .glob ("*_test.py" ) + glob .glob ("test_*.py" )
190
190
test_list .extend (glob .glob ("tests" ))
191
+
191
192
if len (test_list ) == 0 :
192
193
print ("No tests found, skipping directory." )
193
- else :
194
- if TEST_CONFIG ["pip_version_override" ]:
195
- pip_version = TEST_CONFIG ["pip_version_override" ]
196
- session .install (f"pip=={ pip_version } " )
197
- """Runs py.test for a particular project."""
198
- if os .path .exists ("requirements.txt" ):
199
- if os .path .exists ("constraints.txt" ):
200
- session .install ("-r" , "requirements.txt" , "-c" , "constraints.txt" )
201
- else :
202
- session .install ("-r" , "requirements.txt" )
203
-
204
- if os .path .exists ("requirements-test.txt" ):
205
- if os .path .exists ("constraints-test.txt" ):
206
- session .install (
207
- "-r" , "requirements-test.txt" , "-c" , "constraints-test.txt"
208
- )
209
- else :
210
- session .install ("-r" , "requirements-test.txt" )
211
-
212
- if INSTALL_LIBRARY_FROM_SOURCE :
213
- session .install ("-e" , _get_repo_root ())
214
-
215
- if post_install :
216
- post_install (session )
217
-
218
- session .run (
219
- "pytest" ,
220
- * (PYTEST_COMMON_ARGS + session .posargs ),
221
- # Pytest will return 5 when no tests are collected. This can happen
222
- # on travis where slow and flaky tests are excluded.
223
- # See http://doc.pytest.org/en/latest/_modules/_pytest/main.html
224
- success_codes = [0 , 5 ],
225
- env = get_pytest_env_vars (),
226
- )
194
+ return
195
+
196
+ if TEST_CONFIG ["pip_version_override" ]:
197
+ pip_version = TEST_CONFIG ["pip_version_override" ]
198
+ session .install (f"pip=={ pip_version } " )
199
+ """Runs py.test for a particular project."""
200
+ concurrent_args = []
201
+ if os .path .exists ("requirements.txt" ):
202
+ if os .path .exists ("constraints.txt" ):
203
+ session .install ("-r" , "requirements.txt" , "-c" , "constraints.txt" )
204
+ else :
205
+ session .install ("-r" , "requirements.txt" )
206
+ with open ("requirements.txt" ) as rfile :
207
+ packages = rfile .read ()
208
+
209
+ if os .path .exists ("requirements-test.txt" ):
210
+ if os .path .exists ("constraints-test.txt" ):
211
+ session .install ("-r" , "requirements-test.txt" , "-c" , "constraints-test.txt" )
212
+ else :
213
+ session .install ("-r" , "requirements-test.txt" )
214
+ with open ("requirements-test.txt" ) as rtfile :
215
+ packages += rtfile .read ()
216
+
217
+ if INSTALL_LIBRARY_FROM_SOURCE :
218
+ session .install ("-e" , _get_repo_root ())
219
+
220
+ if post_install :
221
+ post_install (session )
222
+
223
+ if "pytest-parallel" in packages :
224
+ concurrent_args .extend (["--workers" , "auto" , "--tests-per-worker" , "auto" ])
225
+ elif "pytest-xdist" in packages :
226
+ concurrent_args .extend (["-n" , "auto" ])
227
+
228
+ session .run (
229
+ "pytest" ,
230
+ * (PYTEST_COMMON_ARGS + session .posargs + concurrent_args ),
231
+ # Pytest will return 5 when no tests are collected. This can happen
232
+ # on travis where slow and flaky tests are excluded.
233
+ # See http://doc.pytest.org/en/latest/_modules/_pytest/main.html
234
+ success_codes = [0 , 5 ],
235
+ env = get_pytest_env_vars (),
236
+ )
227
237
228
238
229
239
@nox .session (python = ALL_VERSIONS )
0 commit comments