Testing the core¶
Targets¶
make test: the JS unit tests (make test-js), then the three apps in parallel withscripts/ci/parallel_tests.py, the splitter CI uses. The dev site is clonedWORKERStimes (default 6; a 7.7 GB Docker VM holds 6), modules are balanced by their last measured time (frappe-bench/logs/test-timings.json), and a failed module is re-run once alone: passing then is reportedFLAKYand does not fail the run. Clone sites are dropped afterwards.make test-serial: one app after another on the dev site, no JS. Use it to follow one failure in order.- Both first check
allow_testsand runffl_core.setup.test_bootstrap.runon the dev site, and both end with oneTOTAL ran=… failures=… errors=…line (the whole run is infrappe-bench/logs/make-test.log). Trust that line: each app prints twoRan Nblocks and the real count is their sum.
The repeatability rule¶
The suite must pass twice back-to-back on the same site. make test cannot show this (its clone sites are rebuilt every run), so run make test-serial twice before a pull request that adds or reworks tests, and compare the TOTALs. A second pass with fewer tests has a setUpClass dying.
Why: IntegrationTestCase (what FrappeTestCase resolves to in Frappe 16) rolls a class back once, at tearDownClass, and frappe.db.rollback() only rewinds to the last commit. Any commit during a test class persists every row before it, and the next run collides (SerialNoDuplicate, "already on file", NegativeStockError).
The run guard¶
Both targets run their test command through scripts/ci/run_guard.py (host side, around the docker compose exec), so a run that cannot be trusted exits non-zero by itself:
- Before the first test: the guard writes a marker under
frappe-bench/logs/and reads it back from/workspaceinside the container. If it is not there, the stack mounts another tree (a worktree whose containers were built from somewhere else), and the run is refused. - After the run: it fails if HEAD or any file that differs from HEAD (edits, staged changes, new untracked files) is not what it was at the start, if no test ran, or if a test file added or modified against the merge-base with
BASE_REF(defaultorigin/develop;make test BASE_REF=<ref>) has no executed test (all its tests skipped is shown in the line, not failed). - The last line is the evidence to paste into a pull request:
run-guard: PASS head=<sha> project=<compose project> ran=<n> changed-test-files=<k> (<module>=<tests executed>, ...). Each failure says what to do about it; there is nothing to switch off.
It counts tests from the runner's own output, so it does not cover JS tests, a new test method in a file that is already collected, or test files outside apps/<app>/<app>/. Do not edit or commit in a checkout while its tests run.
A green run that means nothing¶
- No
allow_testson the site: Frappe runs zero tests and exits 0.make testrefuses such a site;make dev-site-createsets the key. - A bench worker alive in the stack (
bench startormake dev-serveleft on): tests that commit enqueue real jobs into the bench's queue, the worker runs them against the test sites while the tests still change the same rows, and modules the change never touched fail with lock errors (1020 / 1205), differently on every run.make testandmake test-serialrefuse such a stack;make dev-down && make dev-upstops it. CI has no worker. - A site you thought was fresh:
dev-site-createnever recreates one. Fresh meansmake dev-site-drop CONFIRM=yesfirst. - Counting the last block on screen instead of the
TOTALline. - A worktree whose test run executed another tree's code, or a changed test file that was never collected: the run guard above refuses both.
- Running it once.
Rules¶
- No real commit inside a test. Our code commits through
ffl_core.utils.commit(), a no-op underfrappe.flags.in_test. Patchfrappe.db.commitfor third-party code the test reaches. Bulk APIs take acommit_eachflag; tests pass0. - Test files do not commit either, including in
setUp/setUpClass. Use unique names and let the class rollback clean up. The few intentional commits carry a comment saying why; read it before removing one. - Shared masters come from
test_bootstrap, seeded idempotently and out of band (Company, chart of accounts, warehouses, POS Profile, custom fields, FastBound test settings, the reconcile masters).setUpClassassumes them.make testandmake dev-bench-clonerun it; on any other new site run it before the first narrowbench run-tests, which otherwise leaves a half-created Company behind.Serial No.manufactureris a Link to Brand although its label says Manufacturer. - Never stub a Frappe primitive with a bare
return_value.get_hooks,get_value,get_alland friends are called by Frappe itself under your code; answer only the doctype / field / hook under test and pass everything else through. Avoid positionalside_effectlists, blanket truthy strings and last-call-wins captures. - If a test passes because something fails, say so in the test. A stub that crashes the code under test can hide a real write.
- One
addCleanup(p.stop)per patcher, never one cleanup stopping a group: cleanups unwind LIFO, which is the only safe order when patches overlap (two modules thatimport frappeshare one object). - Guard what a stub cannot see, and prove each guard by re-introducing the defect: the doctype column contract (
ffl_core/tests/test_counter_doctype_contracts.py), Singles reads against the real table (ffl_core/tests/test_single_reads.py), the doctype three-file contract (test_doctype_three_file_contract.py). - Mock every document fetch the code under test uses (
get_doc,get_cached_doc,get_last_doc), or letget_value("DocType", …)through: otherwise the bench loads the real controller, the module lookup answersNone, and Frappe looks for the DocType in Core. - A permission gate is verified only through the real call path (HTTP with real credentials). A 403 can mean "no permission" or "record does not exist" (Frappe disguises the second); check which before widening any permission. After the gate, report a missing record explicitly.
- A new DocType is three files: JSON,
__init__.pyand the controller (child tables too). Missing one passes every unit test and fails atbench migrate. - Seed on both
after_installandafter_migrate. A freshnew-site+install-appruns no migrate. Assert both hooks by readinghooks.py, notfrappe.get_hooks(). - Dev fixtures:
bench consolefrom stdin ends a function at a blank line (run a file withexec(compile(...))); commit seed scripts in stages; generate UPCs with a valid check digit;frappe.get_allwithoutlimitreturns 20 rows.
Upgrade watch list¶
Check these on every make ci-upgrade-test; each relies on Frappe or ERPNext internals and fails silently.
| Point | Relies on | Tell |
|---|---|---|
ffl_core/workspace_shortcuts.py::_save_workspace sets frappe.flags.in_patch around ws.save() |
Workspace.on_update → disable_saving_as_public skipping only export / rename work; since Frappe 16.50 also what lets a standard workspace be saved outside developer mode |
gun_shop.json comes back modified, or its modified bumps, after an FFL Settings save |
ffl_core/tests/test_dealer_onboarding.py::_forget_resolved_outgoing_account writes frappe.local.outgoing_email_account |
the private memo of cache_email_account |
the two Mode-A tests fail on the second same-site run |
ffl_core/setup/pos_compat.py: ensure_cashier_pos_profile_select, ensure_role_grants, REGISTER_GRANTS write Custom DocPerm rows |
Custom DocPerm replaces a doctype's shipped DocPerm rows wholesale, freezing them | check_perm_drift (after_migrate) raises an Error Log + ToDo per difference; still git diff the permissions of POS Profile, POS Invoice, POS Opening / Closing Entry, Sales Invoice and Item Price, and run test_counter_register_perms |
ffl_core/api/pos_serial.py overrides erpnext.stock.doctype.serial_no.serial_no.get_pos_reserved_serial_nos (a copy of the upstream query plus a "not consolidated" filter) |
pos_controller.js::check_serial_no_availablilty calling that exact method path, and the upstream query staying as copied |
test_pos_serial fails, or a gun sold at the register and bought back is refused with "has already been transacted into another POS Invoice"; diff the upstream function against the copy |
Sidebars: ffl_core / ffl_integrations ship Sidebar records; mirror_gun_shop_sidebar writes extension modules' |
Frappe 16.50's Sidebar (the old Workspace Sidebar is an archive) |
when a bump touches frappe/desk/doctype/sidebar, check navigation in a browser on a fresh and a migrated site (serve each on its own port) |