From 969abeda24591e1fb15942ffdd88fe36ceb78a25 Mon Sep 17 00:00:00 2001
From: Anthonios Partheniou <partheniou@google.com>
Date: Fri, 10 Jun 2022 18:25:26 +0000
Subject: [PATCH 1/2] prerelease dependencies

---
 noxfile.py | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 65 insertions(+)

diff --git a/noxfile.py b/noxfile.py
index af6ae3f8..05a0501e 100644
--- a/noxfile.py
+++ b/noxfile.py
@@ -19,6 +19,7 @@
 from __future__ import absolute_import
 import os
 import pathlib
+import re
 import shutil
 import warnings
 
@@ -324,3 +325,67 @@ def docfx(session):
         os.path.join("docs", ""),
         os.path.join("docs", "_build", "html", ""),
     )
+
+
+@nox.session(python=SYSTEM_TEST_PYTHON_VERSIONS)
+def prerelease_deps(session):
+    """Run all tests with prerelease versions of dependencies installed."""
+
+    prerel_deps = [
+        "protobuf",
+        "googleapis-common-protos",
+        "google-auth",
+        "grpcio",
+        "grpcio-status",
+        "google-api-core",
+        "proto-plus",
+        # dependencies of google-auth
+        "cryptography",
+        "pyasn1",
+    ]
+
+    for dep in prerel_deps:
+        session.install("--pre", "--no-deps", "--upgrade", dep)
+
+    # Remaining dependencies
+    other_deps = ["requests"]
+    session.install(*other_deps)
+
+    session.install(*UNIT_TEST_STANDARD_DEPENDENCIES)
+    session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES)
+
+    # Because we test minimum dependency versions on the minimum Python
+    # version, the first version we test with in the unit tests sessions has a
+    # constraints file containing all dependencies and extras.
+    with open(
+        CURRENT_DIRECTORY
+        / "testing"
+        / f"constraints-{UNIT_TEST_PYTHON_VERSIONS[0]}.txt",
+        encoding="utf-8",
+    ) as constraints_file:
+        constraints_text = constraints_file.read()
+
+    # Ignore leading whitespace and comment lines.
+    deps = [
+        match.group(1)
+        for match in re.finditer(
+            r"^\s*(\S+)(?===\S+)", constraints_text, flags=re.MULTILINE
+        )
+    ]
+
+    # Don't overwrite prerelease packages.
+    deps = [dep for dep in deps if dep not in prerel_deps]
+    # We use --no-deps to ensure that pre-release versions aren't overwritten
+    # by the version ranges in setup.py.
+    session.install(*deps)
+    session.install("--no-deps", "-e", ".[all]")
+
+    # Print out prerelease package versions
+    session.run(
+        "python", "-c", "import google.protobuf; print(google.protobuf.__version__)"
+    )
+    session.run("python", "-c", "import grpc; print(grpc.__version__)")
+
+    session.run("py.test", "tests/unit")
+    session.run("py.test", "tests/system")
+    session.run("py.test", "samples/snippets")

From 87914780e2d6b4d0e86b6da6f237594899cdf98f Mon Sep 17 00:00:00 2001
From: Anthonios Partheniou <partheniou@google.com>
Date: Fri, 10 Jun 2022 18:41:34 +0000
Subject: [PATCH 2/2] add kokoro configs

---
 .kokoro/continuous/prerelease-deps.cfg | 7 +++++++
 .kokoro/presubmit/prerelease-deps.cfg  | 7 +++++++
 2 files changed, 14 insertions(+)
 create mode 100644 .kokoro/continuous/prerelease-deps.cfg
 create mode 100644 .kokoro/presubmit/prerelease-deps.cfg

diff --git a/.kokoro/continuous/prerelease-deps.cfg b/.kokoro/continuous/prerelease-deps.cfg
new file mode 100644
index 00000000..3595fb43
--- /dev/null
+++ b/.kokoro/continuous/prerelease-deps.cfg
@@ -0,0 +1,7 @@
+# Format: //devtools/kokoro/config/proto/build.proto
+
+# Only run this nox session.
+env_vars: {
+    key: "NOX_SESSION"
+    value: "prerelease_deps"
+}
diff --git a/.kokoro/presubmit/prerelease-deps.cfg b/.kokoro/presubmit/prerelease-deps.cfg
new file mode 100644
index 00000000..3595fb43
--- /dev/null
+++ b/.kokoro/presubmit/prerelease-deps.cfg
@@ -0,0 +1,7 @@
+# Format: //devtools/kokoro/config/proto/build.proto
+
+# Only run this nox session.
+env_vars: {
+    key: "NOX_SESSION"
+    value: "prerelease_deps"
+}