Skip to content

Commit

Permalink
tests: Add a session for system tests against the emulator. (#969)
Browse files Browse the repository at this point in the history
* tests: Add a session for system tests against the emulator.

* 🦉 Updates from OwlBot post-processor

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

---------

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
  • Loading branch information
sorced-jim and gcf-owl-bot[bot] committed Mar 13, 2024
1 parent 66e61cc commit 8f4486f
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
4 changes: 3 additions & 1 deletion CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
46 changes: 46 additions & 0 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import os
import pathlib
import shutil
import signal
import subprocess

import nox

Expand Down Expand Up @@ -91,6 +93,50 @@ 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:
Expand Down

0 comments on commit 8f4486f

Please sign in to comment.