Document use of `--no-window` option for command line and vscode plugin
Per #357, you can use the --no-window Godot command line option to hide the Godot window when running tests. You can also add this option to the "Additional Options" in the VSCode GUT Extension. This should be documented somewhere so it's easier to find by others. There are also some considerations to make when using it.
- The "should exit" option should be specified, otherwise you have to break out at the end of the run. If the option is detectable then GUT should take appropriate action and exit.
- Calls to
pause_before_teardownwill cause the tests to hang since you won't be able to see the screen to click "continue". Again, if the option is detectable GUT can take the right action here. - You should specify the "ignore pause" option per the previous point.
- You of course cannot watch your tests run.
I could not find a way to auto-detect that Godot is running in headless or "no window" mode. An option should be added that will override settings and take other actions to make running without a window more user friendly.
- should_exit = true
- should_exit_on_success = false
- ignore_pauses = true
- disable GUI printer (saves some cycles)
Thanks much for GUT - it's been a good experience to start working with it today!
Apologies for the large comment here - I was hoping to turn this into a PR, but couldn't find a way to make it work, so here's my notes instead.
I was curious about enabling --no-window from the GUT panel, to prevent an extra window from opening when running tests through the editor, but once I found this issue, I thought I'd dig in. I'm pretty new to digging into godot internals, so take all this with a grain of salt!
One thing is that --no-window has been removed in favor of --headless in this commit: https://github.com/godotengine/godot/commit/09386ba9fd6abddb3b9be723ae3650c6d15bc440 So that command line option shift at some point (maybe in 3.5?).
It looks like DisplayServer - window_can_draw will soon be a preferred way to check for this (internally in godot, anyway): https://github.com/godotengine/godot/commit/39efccf3b8298e30aa67a726ffd8752b3dff4c66 In the meantime: OS::get_singleton()->can_draw() && !OS::get_singleton()->is_no_window_mode_enabled() seems to be the 3.x compatible version (https://github.com/godotengine/godot/pull/50767#discussion_r688335782).
I couldn't find anything like this available in gdscript, expect for OS.can_draw(), which unfortunately seems to return true regardless of --no-window.
I thought maybe OS.get_cmdline_args() would include --no-window, but it seems to be cleared/removed before the shell script runs, so it doesn't show up in that array.
The Godot OS class itself does not expose anything directly helpful, despite the OS singleton in godot's source maintaining a _no_window bool - perhaps this has just never been requested, so it's not exposed? Or maybe there's some idea that people will use the "headless" godot builds directly for cases like this?
I tried a few different things in a script:
#!/usr/bin/env -S godot -s --no-window
extends SceneTree
func _init():
print("os can draw: ", OS.can_draw())
print("os props: ", OS.get_property_list())
# for p in OS.get_property_list():
# print(p.name)
# print(" " + p.name + ": ", OS.get(p.name))
print("window position: ", OS.get_window_position())
print("no window: ", OS.get_window_position() == Vector2.ZERO)
# print("minimized: ", OS.window_minimized)
quit()
One hacky option is something like: OS.get_window_position() == Vector2.ZERO, which isn't perfect but might be right in most cases? Not the best solution, there might be weird cases that break it (some strange window managers? windows?). If you don't mind using the window_position like this, I can take a shot at a PR that fixes the non-interactive options you listed.
It seems there's no way to opt-in to --no-window behavior from gdscript, at least not without a PR to godot itself that exposes more of the OS singleton. If there are workarounds for doing this, I'm very interested! I'm trying to get a better grasp of gdscript + godot in general, especially for more command-line tools like this.
You can also add this option to the "Additional Options" in the VSCode GUT Extension. This should be documented somewhere so it's easier to find by others. There are also some considerations to make when using it.
Do you want to talk about it there https://github.com/bitwes/gut-extension#gut-extensionadditionaloptions in Possible Uses ?
Like
- add
--no-windowto hide the Godot window when running tests
I tested it, it works :) !