[Python] How to test Firebase Callable Function concurrency locally using Python and the...

Discussão em 'Python' iniciado por Stack, Julho 4, 2025.

  1. Stack

    Stack Membro Participativo

    I'm working with Firebase Functions (Python) and trying to test a Callable HTTPS function that performs a Firestore transaction. Here's a simplified version of the function:

    @https_fn.on_call()
    def increment(req: https_fn.CallableRequest) -> any:
    db = firestore.client()
    uid = req.auth.uid
    transaction = db.transaction()
    doc_ref = db.collection("numbers").document(uid)
    result = function(transaction,doc_ref)

    @firestore.transactional
    def function(transaction , ref ):
    doc = ref.get(transaction = transaction)
    data = doc.to_dict()
    if data.get('count') < 10:
    transaction.update(ref, {'count': firestore.Increment(1)})

    return True



    What I’m Trying to Do:

    I want to test this function locally using firebase emulator under concurrent access using unit tests.

    Challenges:

    1. There seems to be no official documentation for unit testing Firebase Functions in Python.
    2. I'm not using standard HTTP functions — this is a Callable HTTPS function, which makes local invocation and concurrency testing a bit trickier since the invocation must happen from authenticated context .

    Currently explored

    1. unit testing(https://firebase.google.com/docs/functions/unit-testing): only found for JS.
    2. interactive shell(https://firebase.google.com/docs/functions/local-shell) : not sure if I can create unit test like condition.

    Continue reading...

Compartilhe esta Página