1<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xml:id="sec-running-nixos-tests-interactively">
2 <title>Running Tests interactively</title>
3 <para>
4 The test itself can be run interactively. This is particularly
5 useful when developing or debugging a test:
6 </para>
7 <programlisting>
8$ nix-build . -A nixosTests.login.driverInteractive
9$ ./result/bin/nixos-test-driver
10[...]
11>>>
12</programlisting>
13 <para>
14 You can then take any Python statement, e.g.
15 </para>
16 <programlisting language="python">
17>>> start_all()
18>>> test_script()
19>>> machine.succeed("touch /tmp/foo")
20>>> print(machine.succeed("pwd")) # Show stdout of command
21</programlisting>
22 <para>
23 The function <literal>test_script</literal> executes the entire test
24 script and drops you back into the test driver command line upon its
25 completion. This allows you to inspect the state of the VMs after
26 the test (e.g. to debug the test script).
27 </para>
28 <section xml:id="sec-nixos-test-reuse-vm-state">
29 <title>Reuse VM state</title>
30 <para>
31 You can re-use the VM states coming from a previous run by setting
32 the <literal>--keep-vm-state</literal> flag.
33 </para>
34 <programlisting>
35$ ./result/bin/nixos-test-driver --keep-vm-state
36</programlisting>
37 <para>
38 The machine state is stored in the
39 <literal>$TMPDIR/vm-state-machinename</literal> directory.
40 </para>
41 </section>
42 <section xml:id="sec-nixos-test-interactive-configuration">
43 <title>Interactive-only test configuration</title>
44 <para>
45 The <literal>.driverInteractive</literal> attribute combines the
46 regular test configuration with definitions from the
47 <link linkend="test-opt-interactive"><literal>interactive</literal>
48 submodule</link>. This gives you a more usable, graphical, but
49 slightly different configuration.
50 </para>
51 <para>
52 You can add your own interactive-only test configuration by adding
53 extra configuration to the
54 <link linkend="test-opt-interactive"><literal>interactive</literal>
55 submodule</link>.
56 </para>
57 <para>
58 To interactively run only the regular configuration, build the
59 <literal><test>.driver</literal> attribute instead, and call
60 it with the flag
61 <literal>result/bin/nixos-test-driver --interactive</literal>.
62 </para>
63 </section>
64</section>