Skip to content
This repository was archived by the owner on Mar 2, 2026. It is now read-only.

Commit 891edc7

Browse files
feat(firestore): add support of emulator to run system tests on emulator (#31)
* feat(firestore): add support of emulator to run system tests on emulator * feat(firestore): add test_utils folder for support * docs(firestore): remove test_utils folder as added in nox file Co-authored-by: Christopher Wilcox <crwilcox@google.com>
1 parent c97a168 commit 891edc7

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

tests/system/test_system.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@
3030
from google.cloud._helpers import _pb_timestamp_to_datetime
3131
from google.cloud._helpers import UTC
3232
from google.cloud import firestore_v1 as firestore
33+
from google.cloud.firestore_v1.client import _FIRESTORE_EMULATOR_HOST
3334
from test_utils.system import unique_resource_id
35+
from test_utils.system import EmulatorCreds
3436

3537
from time import sleep
3638

@@ -41,11 +43,19 @@
4143
DOCUMENT_EXISTS = "Document already exists: "
4244
UNIQUE_RESOURCE_ID = unique_resource_id("-")
4345

46+
FIRESTORE_EMULATOR = os.getenv(_FIRESTORE_EMULATOR_HOST) is not None
47+
4448

4549
@pytest.fixture(scope=u"module")
4650
def client():
47-
credentials = service_account.Credentials.from_service_account_file(FIRESTORE_CREDS)
48-
project = FIRESTORE_PROJECT or credentials.project_id
51+
if FIRESTORE_EMULATOR:
52+
credentials = EmulatorCreds()
53+
project = FIRESTORE_PROJECT
54+
else:
55+
credentials = service_account.Credentials.from_service_account_file(
56+
FIRESTORE_CREDS
57+
)
58+
project = FIRESTORE_PROJECT or credentials.project_id
4959
yield firestore.Client(project=project, credentials=credentials)
5060

5161

@@ -126,6 +136,7 @@ def test_create_document_w_subcollection(client, cleanup):
126136
assert sorted(child.id for child in children) == sorted(child_ids)
127137

128138

139+
@pytest.mark.skipif(FIRESTORE_EMULATOR, reason="Internal Issue b/137866686")
129140
def test_cannot_use_foreign_key(client, cleanup):
130141
document_id = "cannot" + UNIQUE_RESOURCE_ID
131142
document = client.document("foreign-key", document_id)
@@ -280,6 +291,7 @@ def test_document_update_w_int_field(client, cleanup):
280291
assert snapshot1.to_dict() == expected
281292

282293

294+
@pytest.mark.skipif(FIRESTORE_EMULATOR, reason="Internal Issue b/137867104")
283295
def test_update_document(client, cleanup):
284296
document_id = "for-update" + UNIQUE_RESOURCE_ID
285297
document = client.document("made", document_id)
@@ -861,6 +873,7 @@ def test_collection_group_queries_filters(client, cleanup):
861873
assert found == set(["cg-doc2"])
862874

863875

876+
@pytest.mark.skipif(FIRESTORE_EMULATOR, reason="Internal Issue b/137865992")
864877
def test_get_all(client, cleanup):
865878
collection_name = "get-all" + UNIQUE_RESOURCE_ID
866879

0 commit comments

Comments
 (0)