@@ -70,7 +70,21 @@ Many tests install workflows for testing. These are installed into cylc-run as
70
70
usual under the prefix ` cylctb ` .
71
71
72
72
73
- ## How To Debug Failing Tests
73
+ ## recording tests that fail
74
+
75
+ When running many tests you can record the tests that fail using
76
+ ` --state=save ` . You can then re-run the only the failed tests using
77
+ ` --state=failed ` .
78
+
79
+ For more details see ` man prove ` .
80
+
81
+
82
+ ## Debugging
83
+
84
+ When a test fails, it may print some directories to the screen which contain
85
+ the stderr of the failed tests, or the workflow logs.
86
+
87
+ Tips:
74
88
75
89
* Run the test using the ` -v ` argument, this will reveal which subtest(s)
76
90
failed.
@@ -79,6 +93,66 @@ usual under the prefix `cylctb`.
79
93
directory will not be deleted, you can inspect the workflow logs there.
80
94
* In GitHub actions, the ` ~/cylc-run ` directory is uploaded as an "artifact"
81
95
where it can be downloaded for debugging.
96
+ * Any text that gets written to stdout will be swallowed by the test framework,
97
+ redirect to stderr in order to use ` echo ` statements for debugging, e.g,
98
+ ` echo "DEBUG: platform=$CYLC_PLATFORM_NAME" >&2 ` .
99
+
100
+
101
+ ### Python Debuggers
102
+
103
+ "Normal" Python debuggers (e.g, ` pdb ` ) will not work from within the functional
104
+ test framework because the Python code maybe run non-interactively.
105
+
106
+ However, you can use remote debuggers
107
+ (e.g. [ ` remote_pdb ` ] ( https://pypi.org/project/remote-pdb/ ) ).
108
+
109
+ Remote PDB is probably the simplest remote debugger, here's a simple example
110
+ to get started:
111
+
112
+ Open two terminal tabs and run this code in both of them:
113
+
114
+ ``` shell
115
+ PYTHONBREAKPOINT=remote_pdb.set_trace
116
+ REMOTE_PDB_HOST=0.0.0.0
117
+ REMOTE_PDB_PORT=${-4444}
118
+ export PYTHONBREAKPOINT REMOTE_PDB_HOST REMOTE_PDB_PORT
119
+ ```
120
+
121
+ Run the test in the first tab, then run this command in the second:
122
+
123
+ ``` shell
124
+ nc -C " $REMOTE_PDB_HOST " " $REMOTE_PDB_PORT "
125
+ ```
126
+
127
+
128
+ ### Traps for the unwary
129
+
130
+ #### ` grep_ok ` vs ` comp_ok `
131
+
132
+ Tests that use ` comp_ok ` generally compare ` ${TEST_NAME}.stdout ` or
133
+ ` ${TEST_NAME}.stderr ` against either a reference or against ` /dev/null ` .
134
+ They expect the entire output to be ** exactly** the same as the
135
+ reference and are therefore very unforgiving.
136
+
137
+ ` grep_ok ` is much less sensitive only requiring the reference output to
138
+ be present ** somewhere** in the test output.
139
+
140
+
141
+ ### Further Reading
142
+
143
+ #### Heredocs
144
+
145
+ If you see code that looks like this:
146
+
147
+ ``` bash
148
+ cat > ' hello.py' << '__HELLO_PY__ '
149
+ print("Hello World")
150
+ __HELLO_PY__
151
+ ```
152
+
153
+ You are looking at an "heredoc" and you may wish to read about heredocs:
154
+ [ A modern looking bloggy guide] ( https://linuxize.com/post/bash-heredoc/ )
155
+ [ A web 1.0 manual] ( http://tldp.org/LDP/abs/html/here-docs.html )
82
156
83
157
84
158
## How To Run "Non-Generic" Tests?
0 commit comments