@@ -188,42 +188,54 @@ 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(
212
+ "-r", "requirements-test.txt", "-c", "constraints-test.txt"
213
+ )
214
+ else:
215
+ session.install("-r", "requirements-test.txt")
216
+ with open("requirements-test.txt") as rtfile:
217
+ packages += rtfile.read()
218
+
219
+ if INSTALL_LIBRARY_FROM_SOURCE:
220
+ session.install("-e", _get_repo_root())
221
+
222
+ if post_install:
223
+ post_install(session)
224
+
225
+ if "pytest-parallel" in packages:
226
+ concurrent_args.extend(['--workers', 'auto', '--tests-per-worker', 'auto'])
227
+ elif "pytest-xdist" in packages:
228
+ concurrent_args.extend(['-n', 'auto'])
229
+
230
+ session.run(
231
+ "pytest",
232
+ *(PYTEST_COMMON_ARGS + session.posargs + concurrent_args),
233
+ # Pytest will return 5 when no tests are collected. This can happen
234
+ # on travis where slow and flaky tests are excluded.
235
+ # See http://doc.pytest.org/en/latest/_modules/_pytest/main.html
236
+ success_codes=[0, 5],
237
+ env=get_pytest_env_vars(),
238
+ )
227
239
228
240
229
241
@nox.session(python=ALL_VERSIONS)
0 commit comments