Testing
assert
Section titled “assert”assert condition raises AssertionError when the condition is false, with an optional message. Unlike Python’s, it’s never compiled away.
def mean(xs: list[float]) -> float: assert len(xs) > 0, "mean of an empty list" return sum(xs) / len(xs)
print(mean([1, 2, 3]))print(mean([]))2.0Traceback (most recent call last): File "main.tpn", line 6, in <module> print(mean([])) File "main.tpn", line 2, in mean assert len(xs) > 0, "mean of an empty list"AssertionError: mean of an empty listtaipan test
Section titled “taipan test”taipan test finds test files, test_*.tpn and *_test.tpn, and runs each one’s test_* functions, as pytest does:
def area(width: float, height: float) -> float: return width * heightfrom shapes import area
def test_area(): assert area(2, 3) == 6.0
def test_negative(): assert area(-1, 2) == 0.0, "a negative side has no area"taipan testPASS test_shapes.tpn::test_areaFAIL test_shapes.tpn::test_negativeTraceback (most recent call last): File "test_shapes.tpn", line 7, in test_negative assert area(-1, 2) == 0.0, "a negative side has no area"AssertionError: a negative side has no area1 passed, 1 failedtaipan testtakes files and directories,.by default.- Each test file is a main file: its top level runs first, then its tests, in order. Tests may be
async. - A test passes if it returns, and fails if it raises anything.
- The exit code is
0when every test passed, and1when one failed, a file had an error, or there were no tests.
Test projects
Section titled “Test projects”In an SDK project, a test project is a .tpnproj with IsTestProject, so dotnet test runs it beside your C# tests:
<Project Sdk="TaipanLang.Sdk/0.4.0"> <PropertyGroup> <IsTestProject>true</IsTestProject> </PropertyGroup> <ItemGroup> <ProjectReference Include="../Acme.Shapes/Acme.Shapes.tpnproj" /> </ItemGroup></Project>Its main file is a test file, and dotnet test writes the same report. See Projects.
Formatting in CI
Section titled “Formatting in CI”taipan fmt --check . lists the files that aren’t formatted and exits 1 if there are any.
© 2026 Discover Edge, LLC · Taipan is released under the MIT License.