Skip to content
This repository was archived by the owner on Feb 1, 2024. It is now read-only.

Commit 5b7ede7

Browse files
chore: Adding support for pytest-xdist and pytest-parallel (#233)
Source-Link: googleapis/synthtool@82f5cb2 Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-python:latest@sha256:5d8da01438ece4021d135433f2cf3227aa39ef0eaccc941d62aa35e6902832ae Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com> Co-authored-by: Anthonios Partheniou <partheniou@google.com>
1 parent 2b35888 commit 5b7ede7

File tree

2 files changed

+45
-35
lines changed

2 files changed

+45
-35
lines changed

.github/.OwlBot.lock.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@
1313
# limitations under the License.
1414
docker:
1515
image: gcr.io/cloud-devrel-public-resources/owlbot-python:latest
16-
digest: sha256:6162c384d685c5fe22521d3f37f6fc732bf99a085f6d47b677dbcae97fc21392
16+
digest: sha256:5d8da01438ece4021d135433f2cf3227aa39ef0eaccc941d62aa35e6902832ae

samples/snippets/noxfile.py

Lines changed: 44 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -188,42 +188,52 @@ def _session_tests(
188188
# check for presence of tests
189189
test_list = glob.glob("*_test.py") + glob.glob("test_*.py")
190190
test_list.extend(glob.glob("tests"))
191+
191192
if len(test_list) == 0:
192193
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+
)
227237

228238

229239
@nox.session(python=ALL_VERSIONS)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy