nixos/manual: Add docs on extra python packages in tests
This commit is contained in:
parent
8858bf009e
commit
2a750c3026
|
@ -380,3 +380,25 @@ with foo_running:
|
|||
def foo_running():
|
||||
machine.succeed("pgrep -x foo")
|
||||
```
|
||||
|
||||
## Adding Python packages to the test script {#ssec-python-packages-in-test-script}
|
||||
|
||||
When additional Python libraries are required in the test script, they can be
|
||||
added using the parameter `extraPythonPackages`. For example, you could add
|
||||
`numpy` like this:
|
||||
|
||||
```nix
|
||||
import ./make-test-python.nix
|
||||
{
|
||||
extraPythonPackages = p: [ p.numpy ];
|
||||
|
||||
nodes = { };
|
||||
|
||||
testScript = ''
|
||||
import numpy as np
|
||||
assert str(np.zeros(4) == "array([0., 0., 0., 0.])")
|
||||
'';
|
||||
}
|
||||
```
|
||||
|
||||
In that case, `numpy` is chosen from the generic `python3Packages`.
|
||||
|
|
|
@ -652,4 +652,30 @@ def foo_running():
|
|||
```
|
||||
</programlisting>
|
||||
</section>
|
||||
<section xml:id="ssec-python-packages-in-test-script">
|
||||
<title>Adding Python packages to the test script</title>
|
||||
<para>
|
||||
When additional Python libraries are required in the test script,
|
||||
they can be added using the parameter
|
||||
<literal>extraPythonPackages</literal>. For example, you could add
|
||||
<literal>numpy</literal> like this:
|
||||
</para>
|
||||
<programlisting language="bash">
|
||||
import ./make-test-python.nix
|
||||
{
|
||||
extraPythonPackages = p: [ p.numpy ];
|
||||
|
||||
nodes = { };
|
||||
|
||||
testScript = ''
|
||||
import numpy as np
|
||||
assert str(np.zeros(4) == "array([0., 0., 0., 0.])")
|
||||
'';
|
||||
}
|
||||
</programlisting>
|
||||
<para>
|
||||
In that case, <literal>numpy</literal> is chosen from the generic
|
||||
<literal>python3Packages</literal>.
|
||||
</para>
|
||||
</section>
|
||||
</section>
|
||||
|
|
Loading…
Reference in a new issue