Skip to content

Commit 5c89a18

Browse files
more developer docs
1 parent 62f5973 commit 5c89a18

File tree

2 files changed

+87
-1
lines changed

2 files changed

+87
-1
lines changed

tests/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Tests
2+
3+
Cylc-flow has three tiers of tests:
4+
5+
| Test Type | Command | Docs |
6+
|---|---|---|
7+
| Unit Tests | `pytest` | [README](https://github.com/cylc/cylc-flow/blob/master/tests/unit/README.md) |
8+
| Integration tests | `pytest tests/integration` | [README](https://github.com/cylc/cylc-flow/blob/master/tests/integration/README.md) |
9+
| Functional Tests | `etc/bin/run-functional-tests` | [README](https://github.com/cylc/cylc-flow/blob/master/tests/functional/README.md) |
10+
11+
The README files in each directory explain what sort of tests should go into
12+
which directory, how to run and debug these tests.

tests/functional/README.md

Lines changed: 75 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,21 @@ Many tests install workflows for testing. These are installed into cylc-run as
7070
usual under the prefix `cylctb`.
7171

7272

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:
7488

7589
* Run the test using the `-v` argument, this will reveal which subtest(s)
7690
failed.
@@ -79,6 +93,66 @@ usual under the prefix `cylctb`.
7993
directory will not be deleted, you can inspect the workflow logs there.
8094
* In GitHub actions, the `~/cylc-run` directory is uploaded as an "artifact"
8195
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)
82156

83157

84158
## How To Run "Non-Generic" Tests?

0 commit comments

Comments
 (0)