seitime-frappe/frappe/tests
Abdeali Chharchhodawala 690826ff9b
feat!: faster generation and formatting utils for excel exports (#36323)
* feat: Style builder for report xlsx formatting

* fix: update report to use direct import for query report execution

* refactor: simplify module method retrieval in report execution

* feat: get xlsx styles for report

* refactor: enhance XLSXStyleBuilder with currency formatting and default style registration

* feat: add xlsxwriter dependency for enhanced XLSX report generation

* refactor: enhance XLSXStyleBuilder with improved style registration and formatting methods

* feat: enhance XLSX export functionality with improved styling and metadata support

* refactor: default formatting of currency

* chore: remove some typo

* feat: update make_xlsx function to use xlsxwriter for improved Excel file generation and styling

* perf: some micro optimisations

* refactor: inline generator back and improve condition

* refactor: replace frappe.request_cache with functools.cache

* fix: handle styling in email

* fix: fix old test case to handle styles in export

* refactor: enhance XLSX style handling and registration methods

* refactor: improve currency formatting logic

* fix: update make_xlsx to use constant_memory for large datasets and improve row style handling

* fix: handle None style_id in XLSXStyleBuilder methods to prevent errors

* fix: include owner field with proper doctype naming

* fix: set default date format in XLSX workbook creation

* fix: pass applied filters to metadata

* fix: getting accurate field info for report view exporting

* chore: Minor changes

* feat: add function to generate default XLSX styles for exports

* feat: integrate default XLSX styles into builder report export functionality

* feat: styles on export docs xlsx

* feat: enhance make_xlsx function to support file path saving

* feat: add make_xls function for creating Excel files in old format and improve sheet name sanitization

* fix: handle default date formatting

* refactor: changes xlsx builder usage

* refactor: update xlsx style builder usage

* refactor: enhance field info retrieval with default field support

* fix: handle update key in report data

* refactor: enhance get_field_info to include options and improve label retrieval

* fix: improve error handling for unsupported file formats and ensure applied filters are set correctly

* refactor: update XLSX header index handling and improve metadata structure

* fix: handle currency formatting in reportview export

* fix: update default date format to datetime format in XLSX creation

* fix: update serial number field in auto email report to use 'sr' instead of 'idx'

* fix: enhance XLSX styling by adding right alignment for specific field types

* chore: remove unused code

* fix: update XLSXMetadata attributes for improved report styling options

* perf: further improve currency styling

* fix: correct column index mapping in XLSX export header

* refactor: optimize indentation style registration in XLSXStyleBuilder

* perf: improve apply_indentations

* fix: reduce more attr lookup

* refactor: remove duplication

* fix: use report name in XLSX export instead of hardcoded title

* fix: remove ignore_visible_idx from XLSXMetadata

* fix: review

* fix: update XLSX style fetching logic in build_xlsx_data function

* fix: add right alignment to date, time, and datetime styles in XLSXStyleBuilder

* fix: simplify number format handling in XLSXStyleBuilder

* fix: register common styles in XLSXStyleBuilder for improved style management

* test: add tests for XLSX styles structure and fieldtype column styles in XLSXStyleBuilder

---------

Co-authored-by: Sagar Vora <16315650+sagarvora@users.noreply.github.com>
2026-04-21 19:07:43 +05:30
..
classes test: Dump log for any stuck test 2025-12-05 13:16:24 +05:30
data test: Add test for lazy_import 2022-08-11 23:53:21 +05:30
utils fix: ruff fixes 2025-12-22 21:06:48 +05:30
__init__.py refactor: organize test contextmanagers (#28041) 2024-10-09 02:09:19 +02:00
README.md refactor: Structure frappe.test.utils (green to green) (#28038) 2024-10-08 15:10:24 +00:00
test_api.py test: use another doctype to avoid test pollution 2026-04-08 10:50:47 +05:30
test_api_v2.py fix: add type hints to whitelisted methods 4 (#37204) 2026-02-20 14:53:08 +05:30
test_assign.py refactor: unit vs integration treewide (#27992) 2024-10-06 09:43:36 +00:00
test_auth.py fix: ruff fixes 2025-12-22 21:06:48 +05:30
test_background_jobs.py perf: faster local attr lookup 2025-03-12 14:03:36 +05:30
test_base_document.py fix: minor improvements to extended class logic 2025-09-09 11:15:17 +05:30
test_boilerplate.py fix(DX): Add patches folder when generating new app boilerplate (#37352) 2026-02-23 11:08:20 +05:30
test_boot.py fix(test): fetch unseen notes 2025-04-21 19:12:46 +05:30
test_caching.py test: Reset mock the right way (#37045) 2026-02-16 06:27:01 +00:00
test_child_table.py refactor: unit vs integration treewide (#27992) 2024-10-06 09:43:36 +00:00
test_client.py fix!: disallow setting link values not matching filters 2026-01-10 13:25:35 +05:30
test_client_cache.py fix: Avoid mixing client cache and redis_wrapper 2025-01-14 15:20:47 +05:30
test_config.py refactor: unit vs integration treewide (#27992) 2024-10-06 09:43:36 +00:00
test_cors.py refactor: unit vs integration treewide (#27992) 2024-10-06 09:43:36 +00:00
test_dashboard_connections.py refactor: unit vs integration treewide (#27992) 2024-10-06 09:43:36 +00:00
test_db.py fix(db): support list of fields in get_value method when cache is True (#37050) 2026-02-16 20:28:38 +05:30
test_db_query.py test: add test cases 2026-03-21 15:00:59 +05:30
test_db_update.py perf(postgres): skip unnecessary migrations due to type mismatch (#34784) 2025-12-29 18:29:22 +05:30
test_defaults.py refactor: seperate blogs into a seperate app (#32737) 2025-07-28 14:35:02 +05:30
test_deferred_insert.py refactor: unit vs integration treewide (#27992) 2024-10-06 09:43:36 +00:00
test_docstatus.py chore: fix typo in new DocStatus constant 2025-03-05 08:29:47 +05:30
test_document.py test: don't hardcode throw-away doctype names 2026-04-08 21:31:04 +05:30
test_document_locks.py refactor: unit vs integration treewide (#27992) 2024-10-06 09:43:36 +00:00
test_domainification.py chore: clean desktop icon controller 2025-12-18 14:20:00 +05:30
test_dynamic_links.py refactor: unit vs integration treewide (#27992) 2024-10-06 09:43:36 +00:00
test_email.py test: modify existing flush and send_after email tests to add delay to flush 2026-03-05 12:43:02 +05:30
test_exporter_fixtures.py refactor: unit vs integration treewide (#27992) 2024-10-06 09:43:36 +00:00
test_fixture_import.py fix: clear cache and prevent data access after DocType deletion (#34307) 2025-10-10 08:00:51 +00:00
test_fmt_datetime.py refactor: unit vs integration treewide (#27992) 2024-10-06 09:43:36 +00:00
test_fmt_money.py refactor: unit vs integration treewide (#27992) 2024-10-06 09:43:36 +00:00
test_form_load.py refactor: seperate blogs into a seperate app (#32737) 2025-07-28 14:35:02 +05:30
test_formatter.py refactor: unit vs integration treewide (#27992) 2024-10-06 09:43:36 +00:00
test_frappe_client.py refactor: support new function style 2025-11-19 21:15:57 +05:30
test_global_search.py fix: global search text, remove hooks 2025-06-18 16:23:36 +05:30
test_goal.py refactor: unit vs integration treewide (#27992) 2024-10-06 09:43:36 +00:00
test_helpers.py refactor: seperate blogs into a seperate app (#32737) 2025-07-28 14:35:02 +05:30
test_hooks.py refactor(treewide): ruff format 2025-09-26 13:16:43 +05:30
test_linked_with.py refactor: unit vs integration treewide (#27992) 2024-10-06 09:43:36 +00:00
test_listview.py refactor: unit vs integration treewide (#27992) 2024-10-06 09:43:36 +00:00
test_local_proxy.py perf: faster LocalProxy (#29181) 2025-01-20 12:49:55 +00:00
test_model_utils.py refactor: unit vs integration treewide (#27992) 2024-10-06 09:43:36 +00:00
test_modules.py fix(test): note customization yields tuple with 3 values 2026-01-02 18:50:24 +05:30
test_monitor.py refactor: unit vs integration treewide (#27992) 2024-10-06 09:43:36 +00:00
test_naming.py feat: Enhance autoname functionality (#36827) 2026-02-07 06:22:28 +00:00
test_nestedset.py feat(qb_query)!: return query object if requested 2025-12-09 11:39:48 +05:30
test_non_nullable_docfield.py refactor: unit vs integration treewide (#27992) 2024-10-06 09:43:36 +00:00
test_oauth20.py fix: OAuth2 absolute authorize, access token and api urls (#34266) 2025-10-09 16:47:38 +05:30
test_password.py refactor: unit vs integration treewide (#27992) 2024-10-06 09:43:36 +00:00
test_password_strength.py test: retry flaky password_strength test thrice 2023-12-20 13:57:48 +05:30
test_patches.py refactor(treewide): ruff format 2025-09-26 13:16:43 +05:30
test_pdf.py refactor: unit vs integration treewide (#27992) 2024-10-06 09:43:36 +00:00
test_perf.py chore: drop some version checks 2025-12-22 21:06:48 +05:30
test_permissions.py test: allow default fields in query 2026-02-02 15:32:39 +05:30
test_printview.py refactor: unit vs integration treewide (#27992) 2024-10-06 09:43:36 +00:00
test_project_meta.py chore: temporarily increase __init__.py length allowance. (#33803) 2025-08-26 12:20:58 +00:00
test_query.py test: ensure fields with accented chars are considered valid 2026-03-26 17:25:51 +05:30
test_query_builder.py perf(query): replace Coalesce with OR IS NULL in func_in (#38336) 2026-04-08 10:57:07 +05:30
test_query_report.py feat!: faster generation and formatting utils for excel exports (#36323) 2026-04-21 19:07:43 +05:30
test_rate_limiter.py fix: Round of rate limit to seconds (#31674) 2025-03-12 10:52:42 +00:00
test_rating.py refactor: unit vs integration treewide (#27992) 2024-10-06 09:43:36 +00:00
test_recorder.py refactor: Structure frappe.test.utils (green to green) (#28038) 2024-10-08 15:10:24 +00:00
test_redis.py refactor: unit vs integration treewide (#27992) 2024-10-06 09:43:36 +00:00
test_removing_orphans.py fix: add test for removing orphan entity 2025-12-08 16:44:13 +05:30
test_rename_doc.py fix: add type hints to whitelisted methods 3 (#37149) 2026-02-20 06:50:19 +00:00
test_reportview.py feat: allow users to export report in background (#33861) 2025-09-05 14:34:55 +00:00
test_safe_exec.py fix: make shared jenv thread-safe 2025-01-15 11:53:00 +05:30
test_scheduler.py fix: granular status in system health report 2025-02-25 10:38:25 +05:30
test_search.py fix: ignore fieldname validating ignore_user_permissions for Link fields (#37942) 2026-03-11 20:54:03 +00:00
test_seen.py refactor: unit vs integration treewide (#27992) 2024-10-06 09:43:36 +00:00
test_sequence.py refactor: unit vs integration treewide (#27992) 2024-10-06 09:43:36 +00:00
test_sitemap.py refactor: seperate blogs into a seperate app (#32737) 2025-07-28 14:35:02 +05:30
test_sqlite_search.py refactor: add queue for indexing docs in sqlite search (#37840) 2026-03-10 16:03:27 +05:30
test_test_utils.py refactor: Rename get_settings -> get_single_value (#32840) 2025-06-09 04:20:29 +00:00
test_trace.py feat: global frappe.in_test flag (#32960) 2025-06-17 19:19:31 +05:30
test_translate.py fix: sync translations from crowdin (#36437) 2026-01-30 06:31:20 +00:00
test_twofactor.py refactor: removed usage of cmd for login (#36801) 2026-02-16 14:09:48 +05:30
test_utils.py fix!: Restrict allowed HTML in msgprints (#37399) 2026-02-23 11:49:15 +00:00
test_virtual_doctype.py refactor: unit vs integration treewide (#27992) 2024-10-06 09:43:36 +00:00
test_webform.py fix!: Remove badly written default portal list views (#35182) 2025-12-14 07:11:45 +00:00
test_website.py feat: move /app to /desk 2025-11-14 23:05:13 +05:30
translation_test_file.txt feat: allow splitting _() function call on multiple lines 2022-03-26 16:18:35 +05:30
ui_test_helpers.py Merge pull request #37318 from AarDG10/fix-types 2026-02-20 12:11:16 +00:00

Frappe Test Framework

This README provides an overview of the test case framework available in Frappe. These utilities are designed to facilitate efficient and effective testing of Frappe applications.

This is different from the frappe.testing module which houses the discovery and runner infrastructure for CLI and CI.

Directory Structure

The test framework is organized into the following structure:

frappe/tests/
├── classes/
│   ├── context_managers.py
│   ├── unit_test_case.py
│   └── ...
├── utils/
│   ├── generators.py
│   └── ...
├── test_api.py
├── test_child_table.py
└── ...

Key Components

  1. Test case classes (UnitTestCase and IntegrationTestCase)
  2. Framework and class specific context managers
  3. Utility functions and generators
  4. Specific test modules for various Frappe components

Test Case Classes

UnitTestCase (classes/unit_test_case.py)

Import convention: from frappe.tests import UnitTestCase

This class extends unittest.TestCase and provides additional utilities specific to the Frappe framework. It's designed for testing individual components or functions in isolation.

Key features include:

  • Custom assertions for Frappe-specific comparisons
  • Utilities for HTML and SQL normalization
  • Context managers for user switching and time freezing

IntegrationTestCase (classes/integration_test_case.py)

Import convention: from frappe.tests import IntegrationTestCase

This class extends UnitTestCase and is designed for integration testing. It provides features for:

  • Automatic site and connection setup
  • Automatic test records loading
  • Automatic reset of thread locals
  • Context managers that depend on a site connection
  • Asserts that depend on a site connection

For a detailed list of context managers, please refer to the code.

Utility Functions and Generators (utils/generators.py)

This module contains utility functions for generating test records and managing test data.

Specific Test Modules

Various test modules (e.g., test_api.py, test_document.py) contain tests for specific Frappe core components and functionalities.

Note that Document tests are collocated alongside each Document module.

Usage

To use these test utilities in your Frappe application tests, you can inherit from the appropriate test case class:

from frappe.tests import UnitTestCase

class MyTestCase(UnitTestCase):
    def test_something(self):
        # Your test code here
        pass

Contributing

When adding new test utilities or modifying existing ones:

  1. Place them in the appropriate directory based on their function.
  2. Update this README to reflect any significant changes in the framework structure or usage.
  3. Ensure that your changes follow the existing coding style and conventions.

Remember to always refer to the actual code for the most up-to-date and detailed information on available methods and their usage.