CM3D-009: Verification: geometry tests in pytest, mesh check on every export, fit coupons

Accepted · 2026-11-12 · @mathisloge

Context

A print that does not fit costs hours and filament, and a large enclosure panel costs a day. The OpenSCAD tests only knew "the geometry is empty" or "an assertion failed", and the runner had to parse the output because OpenSCAD exits with code 0 on a failed assertion. With exact geometry in Python, tests can say what overlaps, by how much and where.

Decision

  • Geometry tests in pytest (tests/common/, tests/tools/, later tests/pod/<module>/), run with cm3d test [-k EXPR] [--fast]. Tests that take more than about a second carry @pytest.mark.slow, and --fast skips them.

  • Assertion helpers in cm3d.tools.testing: assert_no_overlap, assert_inside, assert_material, assert_open and assert_solids. Each failure message says by how much and where, and each helper also fails if an operand has no volume, so a test cannot pass because a part is empty.

  • Design intent as tests: one test function per intent, named after it (test_nut_sits_fully_on_thread), as plain asserts on params and derived values.

  • Fail once: every new collision or probe test is made to fail once on purpose, and the commit body says so.

  • Mesh check on every export: every STL must be watertight, fit the build volume of 240 × 210 × 260 mm and touch the bed with at least 50 mm² (unless check_bed=False). Overhang regions steeper than 45° are listed and not failed.

  • Fit coupons with coverage: every calibrated fit has a feature on a fit coupon or an entry in COUPON_EXEMPT with its reason, and a test checks it. The first coupon is the common fit coupon in cm3d.common.

  • Bill of materials check: cm3d bom --check and a pre-commit hook verify that the generated pages match the bom.py data.

  • Looking at the part: a rendered picture with a cut through every bore, slot and pocket is part of finishing a part.

Alternatives considered

  • Only the old collision-by-empty-geometry checks: They cannot count solids, select faces or name an overlap.

  • Tests only for the final assembly: They find collisions late and say little about the cause. Part-level intent tests point at the field.

  • Print the part to find out: The coupon does this for the fits, but it is too slow for every dimension.

Consequences

  • Good: Failures name the overlap volume and its box, and a query such as "exactly six rib pieces touch the bearing ring" is one assert.

  • Good: Bad exports are caught before the slicer.

  • Good: One test runner and one language for all checks.

  • Bad: Booleans on large parts can be slow, so the slow marker has to be used with care.

  • Bad: The mesh check lists overhang regions but cannot judge them, so a person still reads the list.