How to open the project in the editor at least once for unit testing

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By DiamondCat

I’m using the GUT (Godot Unit Test) plugin for my project unit testing needs and it has been great so far. However, I’m running into trouble testing localization and following error on my remote CI/CD pipeline. I assume I will be running into the same problem testing any other imported resources in the future.

ERROR: Cannot open file 'res://localization/character_descriptions.en.translation'.
   at: load_interactive (core/io/resource_format_binary.cpp:939)
ERROR: Failed loading resource: res://localization/character_descriptions.en.translation. Make sure resources have been imported by opening the project in the editor at least once.
   at: _load (core/io/resource_loader.cpp:270)

Running the unit tests manually works fine on my developer PC because loading resources has already been done on my workspace. But running unit tests on remote CI/CD pipeline and freshly copied Git repo doesn’t work because the project has not been opened in the editor. I tried fixing this by running headless Godot editor at least once before running the tests. For example, here’s a Dockerfile that automates the tests (using barichello/godot-ci image).

FROM barichello/godot-ci:3.5.1
WORKDIR /tests
COPY . /tests
RUN godot --path "$PWD" --editor --quit --no-window
CMD ["godot", "-s", "addons/gut/gut_cmdln.gd", "-d", "--path", "$PWD", "-ginclude_subdirs", "-gdir=res://tests", "-gexit"]

The RUN command logs same error as above and does not initialize the .import folder correctly. Unit tests run properly with this setup and without the extra RUN command as long as I disable the tests that require resources to be loaded.

I’ve set my .gitignore file to ignore the Godot .import folder since that was recommended. But is removing that ignore only way to solve this? Or maybe testing loaded resources is out of scope for GUT and there’s a better solution?

:bust_in_silhouette: Reply From: DiamondCat

After experimenting with Godot command line options I couldn’t find a solution that would initialize the freshly copied project from Git properly. I ended up removing .import/ and *.translation from my .gitignore file and this seems to work for now.