一键导入
testing
Guidelines for running and writing tests in this project. Patterns, what to test, how to write assertions.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Guidelines for running and writing tests in this project. Patterns, what to test, how to write assertions.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
How to use the library code provided by mi-ni. Code design patterns that abstract compute to easily scale experiments. Read to learn about the `mini` package, the `Apparatus` class, hyperparameter schedulers, notebook/visualization utils, and how to author, run, and monitor memoized experiments from the CLI. These should be used by default.
Render a report in a headless browser. Works offline by bundling Marimo assets.
Writing style for composing text. Use for any prose: Markdown, GitHub issues & PRs, proposals, and technical writing such as academic papers. Improves collaboration effectiveness.
Guidelines for using Modal in this project. Patterns for distributed processing, remote execution, and handling large objects. How to write functions that can be run both locally and remotely.
Write alt text for images. Defines what constitutes "good" alt text. Use when adding images to a documents. a11y is for LLMs as well as humans.
| name | testing |
| description | Guidelines for running and writing tests in this project. Patterns, what to test, how to write assertions. |
This project uses pytest.
Prefer specialized testing utilities, and specify tolerances.
- assert np.allclose(x, y) # ❌
- assert torch.allclose(a, b) # ❌
+ np.testing.assert_allclose(x, y, rtol=1e-7, atol=0) # ✅
+ torch.testing.assert_close(a, b, rtol=1e-7, atol=0) # ✅
Reason: Specialized testing utilities will give you better error messages when assertions fail, and they often have additional features that make them more powerful and flexible than generic assertions. Tolerances are highly context-dependent, so choose them based on principle.
Use structural assertions.
+ from unittest.mock import ANY
- assert "x" in props and approx(props["x"]) == 1.0 # ❌
- assert "z" in props and approx(props["z"]) == 0.8 # ❌
+ assert approx(props) == {"x": 1.0, "y": ANY, "z": 0.8} # ✅
Reason: Structural assertions that fail will show you the entire structure and all the differences, not just the first failed assertion. This makes it much easier to understand what went wrong.
Use reserved domains to avoid accidentally fetching from real domains: .example, .test, .invalid.
- response = requests.get("test.com") # ❌ this is a real domain!
+ response = requests.get("service.test") # ✅ guaranteed not to resolve
Reason: Using real resources in tests can lead to flaky tests and unintended side effects.
Use explicit, literal pre-conditions:
- input = np.arange(5) * 2 # ❌ have to mentally evaluate this
+ input = [0, 2, 4, 6, 8] # ✅ immediately clear what the input is
Reason: Bugs can hide in complex test setup code.
Use explicit, closed-form analytical expected values:
output = add(a, b)
- assert output == a + b # ❌ tautological assertion; doesn't verify anything
+ assert output == 5 # ✅ verifies that the function produces the expected result
Reason: A tautological assertion could easily share the same bug as the code under test, and thus fail to catch it. Analytical expected values can be verified by hand.
Use pytest.mark.parametrize to test multiple cases without repetition.
We only write valuable tests. We test for behavioral verification under uncertainty:
Valuable tests fail for interesting reasons — they break when you've actually broken something that matters to users. We rely on linters and type-checkers for everything else.
When you have finished, review your work with a critical eye. Ask yourself: Does this test actually verify something meaningful? Is it clear what the test is doing and why? Could it be simplified without losing value?