How to Test Frappe Functions with the Console| Sabbirz | Blog

How to Test Frappe Functions with the Console

Test Frappe Functions with the Console

Use the Frappe Console to Debug Your Functions

Sometimes you want to quickly test a function in your custom Frappe app without setting up a full UI or writing extra boilerplate code. In this post, I’ll walk you through how to test your custom method using the Frappe console — a super useful tool for any Frappe developer.


📁 File Structure & Function Location

Let’s say you’ve written a function inside this file:

apps/split/split/api.py

Here’s what the api.py file looks like:

import frappe

@frappe.whitelist()
def get_summary_for_session_user():
    current_user = frappe.session.user
    return get_summary_for_user(current_user)

def get_summary_for_user(current_user: str) -> dict:
    print("current_user is:", current_user)

    debit_amount = frappe.db.get_all(
        "Split Ledger Entry",
        filters={"debit_user": current_user},
        fields=["amount as total_debit_amount", "currency", "credit_user"],
        group_by="credit_user, currency"
    )

    credit_amount = frappe.db.get_all(
        "Split Ledger Entry",
        filters={"credit_user": current_user},
        fields=["SUM(amount) as total_credit_amount", "currency", "debit_user"],
        group_by="debit_user, currency"
    )

    print("debit_amount is:", debit_amount)
    print("credit_amount is:", credit_amount)

    return {
        "debit": debit_amount,
        "credit": credit_amount
    }

💾 Step 1: Make Sure Bench Is Running

Before using the console, ensure your Frappe development server is up and running:

bench start

🥸 Step 2: Open the Frappe Console

Open the Frappe console with your site using:

bench --site siteName console --autoreload

Replace siteName with the actual name of your site.


🔁 Step 3: Import and Call Your Function

Since your function is located at apps/split/split/api.py, you can import and test it like this:

from split.api import get_summary_for_user

get_summary_for_user("nafis@gmail.com")

You’ll get an output similar to:

current_user is:  nafis@gmail.com

debit_amount is:  [
  {'total_debit_amount': 533.33, 'currency': 'BDT', 'credit_user': 's@gmail.com'},
  {'total_debit_amount': 533.33, 'currency': 'BDT', 'credit_user': 'murad@gmail.com'},
  {'total_debit_amount': 533.33, 'currency': 'BDT', 'credit_user': 'faisal@gmail.com'}
]

credit_amount is:  [
  {'total_credit_amount': 175.0, 'currency': 'BDT', 'debit_user': 'Administrator'},
  {'total_credit_amount': 633.33, 'currency': 'USD', 'debit_user': 'Administrator'}
]

That’s it! You now know how to test your custom Frappe methods directly from the console — a huge time saver for development and debugging.

Related posts