From ef1fcfeed644a579ac3e8705a5971f9e970d1c31 Mon Sep 17 00:00:00 2001 From: Jim Morrison Date: Sun, 10 Mar 2024 02:47:30 +0000 Subject: [PATCH 1/2] tests: Add a session for system tests against the emulator. --- CONTRIBUTING.rst | 4 +++- noxfile.py | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index 6d2142c9..0e13c7b0 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -159,7 +159,9 @@ Running System Tests run all the tests. - System tests may be run against the emulator. To do this, set the - ``DATASTORE_EMULATOR_HOST`` environment variable. + ``DATASTORE_EMULATOR_HOST`` environment variable. Alternatively, + system tests with the emulator can run with + `nox -e emulator-system-PYTHON_VERSION` - System tests will be run against an actual project and so you'll need to provide some environment variables to facilitate diff --git a/noxfile.py b/noxfile.py index 2c6bbcb5..844e8752 100644 --- a/noxfile.py +++ b/noxfile.py @@ -20,6 +20,8 @@ import os import pathlib import shutil +import signal +import subprocess import nox @@ -91,6 +93,39 @@ def cover(session): session.run("coverage", "erase") +@nox.session(name="emulator-system", python=ALL_INTERPRETERS) +def emulator_system(session): + """Run the system test suite.""" + # Only run the emulator tests manually. + if not session.interactive: + return + + constraints_path = str( + CURRENT_DIRECTORY / "testing" / f"constraints-{session.python}.txt" + ) + system_test_folder_path = os.path.join("tests", "system") + + # Install all test dependencies, then install this package into the + # virtualenv's dist-packages. + session.install("pytest") + session.install("google-cloud-testutils") + for local_dep in LOCAL_DEPS: + session.install(local_dep) + session.install(".", "-c", constraints_path) + + # TODO: It would be better to allow the emulator to bind to any port and pull + # the port from stderr. + emulator_args = ["gcloud", "emulators", "firestore", "start", + "--database-mode=datastore-mode", "--host-port=localhost:8092"] + emulator = subprocess.Popen(emulator_args, stderr=subprocess.PIPE) + # Run py.test against the system tests. + session.run("py.test", "--quiet", system_test_folder_path, *session.posargs, + env={"DATASTORE_EMULATOR_HOST": "localhost:8092"}) + session.run("curl", "-d", "", "localhost:8092/shutdown", external=True) + emulator.terminate() + emulator.wait(timeout=2) + + def run_black(session, use_check=False): args = ["black"] if use_check: From 6c0b658684faccc91359e5fe5808bcb16cfe3ea6 Mon Sep 17 00:00:00 2001 From: Owl Bot Date: Wed, 13 Mar 2024 04:04:38 +0000 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=A6=89=20Updates=20from=20OwlBot=20po?= =?UTF-8?q?st-processor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --- noxfile.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/noxfile.py b/noxfile.py index 844e8752..cb3c686f 100644 --- a/noxfile.py +++ b/noxfile.py @@ -115,12 +115,23 @@ def emulator_system(session): # TODO: It would be better to allow the emulator to bind to any port and pull # the port from stderr. - emulator_args = ["gcloud", "emulators", "firestore", "start", - "--database-mode=datastore-mode", "--host-port=localhost:8092"] + emulator_args = [ + "gcloud", + "emulators", + "firestore", + "start", + "--database-mode=datastore-mode", + "--host-port=localhost:8092", + ] emulator = subprocess.Popen(emulator_args, stderr=subprocess.PIPE) # Run py.test against the system tests. - session.run("py.test", "--quiet", system_test_folder_path, *session.posargs, - env={"DATASTORE_EMULATOR_HOST": "localhost:8092"}) + session.run( + "py.test", + "--quiet", + system_test_folder_path, + *session.posargs, + env={"DATASTORE_EMULATOR_HOST": "localhost:8092"}, + ) session.run("curl", "-d", "", "localhost:8092/shutdown", external=True) emulator.terminate() emulator.wait(timeout=2)