A testing framework for OpenSCAD scripts
Project description
openscad_test
A testing framework for OpenSCAD scripts, built with uv and available on PyPI.
Installation
pip install openscad-test
Requirements
- Python 3.11 or later
- OpenSCAD installed and available on your system
PATH
Usage
Create one or more .scadtest files describing your tests, then run:
openscad-test mymodule.scadtest
You can pass multiple files at once:
openscad-test tests/basic.scadtest tests/advanced.scadtest
Output
Each test prints its name followed by PASSED or FAILED. When a test
fails, the relevant ECHO, WARNING, and ERROR lines from OpenSCAD are shown.
After all tests have run, a summary is printed:
Echo Integer Test PASSED
Expected Failure Test PASSED
No Warnings Test PASSED
Bad Echo Test FAILED
Expected echo not found: ECHO: 99
ECHO: 42
3 of 4 tests passed, 1 failed.
The process exits with code 0 if all tests pass, or 1 if any test fails.
The .scadtest File Format
A .scadtest file is a TOML file. Each test is defined
as a [[test]] section.
Fields
| Field | Type | Default | Description |
|---|---|---|---|
name |
string | "Unnamed Test" |
Human-readable test name |
script |
string | — | Inline OpenSCAD script to run |
script_file |
string | — | Path to a .scad file (relative to the .scadtest file) |
set_vars |
table | {} |
Variables to pass to the script via -D |
expect_success |
bool | true |
Whether OpenSCAD should complete without errors |
assert_echoes |
list of strings | [] |
Each string must appear (as a substring) in an ECHO output line |
assert_no_echoes |
bool | true |
Assert that there are no ECHO output lines (skipped when assert_echoes is non-empty) |
assert_warnings |
list of strings | [] |
Each string must appear (as a substring) in a WARNING line |
assert_no_warnings |
bool | true |
Assert that there are no WARNING lines (skipped when assert_warnings is non-empty) |
Exactly one of script or script_file must be provided for each test.
Example
[[test]]
# A test that should succeed and produce a specific echo.
name = "Echo Integer Test"
script = "echo(42);"
expect_success = true
assert_echoes = ["ECHO: 42"]
[[test]]
# Pass variables into the script using set_vars.
name = "Set Vars Test"
script = "echo(w);"
set_vars = {w = 10}
expect_success = true
assert_echoes = ["ECHO: 10"]
[[test]]
# A test that expects OpenSCAD to report an error.
# Set assert_no_echoes/assert_no_warnings to false for expected-failure tests
# since OpenSCAD may emit warnings before failing.
name = "Expected Failure Test"
script = "this_function_does_not_exist();"
expect_success = false
assert_no_echoes = false
assert_no_warnings = false
[[test]]
# A test using an external .scad file with no echoes or warnings.
# assert_no_echoes and assert_no_warnings are true by default.
name = "No Warnings Test"
script_file = "my_module.scad"
expect_success = true
Python API
You can also use openscad_test programmatically:
from openscad_test import parse_scadtest_file, run_test
tests = parse_scadtest_file("mymodule.scadtest")
for test_case in tests:
result = run_test(test_case)
if result.passed:
print(f"{test_case.name} PASSED")
else:
print(f"{test_case.name} FAILED")
for msg in result.messages:
print(f" {msg}")
License
MIT
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file openscad_test-1.0.4.tar.gz.
File metadata
- Download URL: openscad_test-1.0.4.tar.gz
- Upload date:
- Size: 22.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b6010a702063ce987252c54e55bd1a25a0145904617845c3c9b4302565cb57e6
|
|
| MD5 |
b0f309928165ff15827c32e8c374d541
|
|
| BLAKE2b-256 |
797d795f920cf251f1ac4c52b717589dc2f2ea3f88ddb39cfbe99b42a660e10d
|
Provenance
The following attestation bundles were made for openscad_test-1.0.4.tar.gz:
Publisher:
publish.yml on BelfrySCAD/openscad_test
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
openscad_test-1.0.4.tar.gz -
Subject digest:
b6010a702063ce987252c54e55bd1a25a0145904617845c3c9b4302565cb57e6 - Sigstore transparency entry: 1114679993
- Sigstore integration time:
-
Permalink:
BelfrySCAD/openscad_test@4730b1fbe58cc5917302a31c70b67555a020b161 -
Branch / Tag:
refs/tags/v1.0.4 - Owner: https://github.com/BelfrySCAD
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@4730b1fbe58cc5917302a31c70b67555a020b161 -
Trigger Event:
push
-
Statement type:
File details
Details for the file openscad_test-1.0.4-py3-none-any.whl.
File metadata
- Download URL: openscad_test-1.0.4-py3-none-any.whl
- Upload date:
- Size: 7.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
13ff02f4a7aadf437419e08f9bb11f666b603f330c5b57c5161f2eeefff910f9
|
|
| MD5 |
5bfeab96ade1ad9a4fce5420e24828a9
|
|
| BLAKE2b-256 |
d678874a4ff7ef824d66ef9161e04e34507bfefcb6fd740e84e97096c46f5ec6
|
Provenance
The following attestation bundles were made for openscad_test-1.0.4-py3-none-any.whl:
Publisher:
publish.yml on BelfrySCAD/openscad_test
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
openscad_test-1.0.4-py3-none-any.whl -
Subject digest:
13ff02f4a7aadf437419e08f9bb11f666b603f330c5b57c5161f2eeefff910f9 - Sigstore transparency entry: 1114680003
- Sigstore integration time:
-
Permalink:
BelfrySCAD/openscad_test@4730b1fbe58cc5917302a31c70b67555a020b161 -
Branch / Tag:
refs/tags/v1.0.4 - Owner: https://github.com/BelfrySCAD
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@4730b1fbe58cc5917302a31c70b67555a020b161 -
Trigger Event:
push
-
Statement type: