NixOS 101 Course / Section 6: NixOS integration tests
Premium

6.3 NixOS test driver features: modules, linting, and machine methods

Lesson 24 of 28 · 9:30

placeholder thumbnail

Sign in, then buy this course to watch

Free account · no credit card needed

Video chapters

  1. 0:00 Module System and Composable Test Definitions
  2. 2:00 Python Linting, Type Checking, and Extra Packages
  3. 4:00 NixOS Test Documentation and Machine Methods
  4. 6:30 Polling Conditions for Faster Test Failures
  5. 8:00 Multinetwork Tests with VLANs
Transcript

Module System and Composable Test Definitions

0:00 Okay, so after we had a brief look at how to write our own NixOS test, let's have a look at a few details, for example, the module system here. In general, runNixOSTest as a function expects a module. So this attribute set, it could itself be like a NixOS module with a function header with pkgs, comma, dot, dot, dot, and stuff like that, right? And then inside that, we can use imports and then merge multiple modules.

0:30 This is really helpful because, for example, you could have basically five times the same network configuration, but always a different test script. Then you would write an attribute set where you have different test scripts each, and then importing the same infrastructure and stuff like that. So the general composability rules like with NixOS modules apply. Defaults, we already mentioned that everything that you put in here would be like normal NixOS configuration, but it would be merged with all your machines there.

1:03 What's also interesting is what many people don't know, we're running a Python linter and a Python type checker over the script. So if that triggers errors while you are just experimenting with your code and try to run something, you can always just turn it off. I've already seen people patching it out instead of just looking into documentation. So here's the hint, look at the documentation and simply disable it if you find it annoying. But for production, it makes sense to keep it in there. The biggest value from the linter and type checker is that if you have a test that, for example, runs one hour, then Python is the kind of language that stumbles upon a syntax error after one hour of running a test case.

The full transcript comes with the lesson.

About this lesson

A tour of the test driver features you will use in real projects, and of where to look up the rest. This lesson covers how tests compose like modules, the checks that run over your test script, extra Python packages, and the methods available on every machine.

In this video

  • Tests as modules: sharing one network setup between several test scripts
  • The linter and type checker that run over your script, how to switch them off
  • Finding the machine methods in the manual and in the driver's Python source
  • Polling conditions that make long tests fail early
  • Multi-network tests with VLANs

After this lesson

You know the building blocks for realistic tests, and where to find the details when you need them.

Links: