diff --git a/nixos/doc/manual/development/writing-nixos-tests.section.md b/nixos/doc/manual/development/writing-nixos-tests.section.md
index e5ee1cb01ff1..583b8f712b41 100644
--- a/nixos/doc/manual/development/writing-nixos-tests.section.md
+++ b/nixos/doc/manual/development/writing-nixos-tests.section.md
@@ -332,6 +332,19 @@ repository):
'';
```
+Similarly, the type checking of test scripts can be disabled in the following
+way:
+
+```nix
+import ./make-test-python.nix {
+ skipTypeCheck = true;
+ nodes.machine =
+ { config, pkgs, ... }:
+ { configuration…
+ };
+}
+```
+
## Failing tests early {#ssec-failing-tests-early}
To fail tests early when certain invariables are no longer met (instead of waiting for the build to time out), the decorator `polling_condition` is provided. For example, if we are testing a program `foo` that should not quit after being started, we might write the following:
diff --git a/nixos/doc/manual/from_md/development/writing-nixos-tests.section.xml b/nixos/doc/manual/from_md/development/writing-nixos-tests.section.xml
index 7ce3e4cb2906..79df3b9c3764 100644
--- a/nixos/doc/manual/from_md/development/writing-nixos-tests.section.xml
+++ b/nixos/doc/manual/from_md/development/writing-nixos-tests.section.xml
@@ -589,6 +589,19 @@ import ./make-test-python.nix {
Python code…
# fmt: on
'';
+
+
+ Similarly, the type checking of test scripts can be disabled in
+ the following way:
+
+
+import ./make-test-python.nix {
+ skipTypeCheck = true;
+ nodes.machine =
+ { config, pkgs, ... }:
+ { configuration…
+ };
+}
diff --git a/nixos/lib/testing-python.nix b/nixos/lib/testing-python.nix
index b76ce3bc3226..8ba2d32ddda5 100644
--- a/nixos/lib/testing-python.nix
+++ b/nixos/lib/testing-python.nix
@@ -50,6 +50,7 @@ rec {
, qemu_pkg ? pkgs.qemu_test
, enableOCR ? false
, skipLint ? false
+ , skipTypeCheck ? false
, passthru ? {}
, interactive ? false
}:
@@ -129,19 +130,21 @@ rec {
vmStartScripts=($(for i in ${toString vms}; do echo $i/bin/run-*-vm; done))
- # prepend type hints so the test script can be type checked with mypy
- cat "${./test-script-prepend.py}" >> testScriptWithTypes
- echo "${builtins.toString machineNames}" >> testScriptWithTypes
- echo "${builtins.toString vlanNames}" >> testScriptWithTypes
- echo -n "$testScript" >> testScriptWithTypes
+ ${lib.optionalString (!skipTypeCheck) ''
+ # prepend type hints so the test script can be type checked with mypy
+ cat "${./test-script-prepend.py}" >> testScriptWithTypes
+ echo "${builtins.toString machineNames}" >> testScriptWithTypes
+ echo "${builtins.toString vlanNames}" >> testScriptWithTypes
+ echo -n "$testScript" >> testScriptWithTypes
- # set pythonpath so mypy knows where to find the imports. this requires the py.typed file.
- export PYTHONPATH='${./test-driver}'
- mypy --no-implicit-optional \
- --pretty \
- --no-color-output \
- testScriptWithTypes
- unset PYTHONPATH
+ # set pythonpath so mypy knows where to find the imports. this requires the py.typed file.
+ export PYTHONPATH='${./test-driver}'
+ mypy --no-implicit-optional \
+ --pretty \
+ --no-color-output \
+ testScriptWithTypes
+ unset PYTHONPATH
+ ''}
echo -n "$testScript" >> $out/test-script
@@ -171,6 +174,7 @@ rec {
, testScript
, enableOCR ? false
, name ? "unnamed"
+ , skipTypeCheck ? false
# Skip linting (mainly intended for faster dev cycles)
, skipLint ? false
, passthru ? {}
@@ -232,13 +236,13 @@ rec {
);
driver = setupDriverForTest {
- inherit testScript enableOCR skipLint passthru;
+ inherit testScript enableOCR skipTypeCheck skipLint passthru;
testName = name;
qemu_pkg = pkgs.qemu_test;
nodes = mkNodes pkgs.qemu_test;
};
driverInteractive = setupDriverForTest {
- inherit testScript enableOCR skipLint passthru;
+ inherit testScript enableOCR skipTypeCheck skipLint passthru;
testName = name;
qemu_pkg = pkgs.qemu;
nodes = mkNodes pkgs.qemu;