Repository navigation
Description
What
- Change
nixos/all-tests.nixto userunTestinstead ofhandleTest. - Change the tests to be modules.
Why
Benefits of runTest and runTestOn:
- Define values for any test option
- Use imports to compose tests
- Access the module arguments like hostPkgs and config.node.pkgs
- Portable to other VM hosts, specifically Darwin
- Faster evaluation, using a single
pkgsinstance - Documented for external use too
How
Many tests are trivial to migrate, but here's the complete guide, also available in a comment in all-tests.nix.
Testing the darwin support is optional and largely unnecessary.
Changes required to migrate to runTest:
-
Remove any
import ../make-test-python.nixor similar calls, leaving only
the callback function. -
Convert the function header to make it a module.
Packages can be taken from the following. For VM host portability, useconfig.node.pkgs.<name>orconfig.nodes.foo.nixpkgs.pkgs.<name>to refer
to the Nixpkgs used on the VM guest(s).hostPkgs.<name>when invoking commands on the VM host (e.g. in Python
os.system("foo"))
-
Since the runTest argument is a module instead of a function, arguments
must be passed as option definitions.
You may declare explicitoptionsfor the test parameter(s), or use the
less explicit_module.args.<name>to pass arguments to the module.Example call with arguments:
runTest { imports = [ ./test.nix ]; _module.args.getPackage = pkgs: pkgs.foo_1_2; } -
If your test requires any definitions in
nixpkgs.*options, set
node.pkgsReadOnly = falsein the test configuration.
Test matrix
Pass the runTest function into the test file and use it instead of make-test-python.nix or similar.
Context
Written as a Nixpkgs maintainer, nothing special.
Activity
286 remaining items
nixosTests.noto-fonts: migrate to runTest
misuzu commentedon Jun 6, 2025
Closed by accident?
Prince213 commentedon Jun 6, 2025
Yeah, you are right.
JohnRTitor commentedon Jun 6, 2025
We might need a treewide change to address this once and for all.
@Prince213 since you have assigned yourself, I assume you want to tackle this?
Prince213 commentedon Jun 6, 2025
Yes, as stated earlier in #410569 (comment). I expect to work on this in the coming week.
rnhmjoj commentedon Jul 11, 2025
Thank you, Prince213.