assign value to an type-annotation varaible got "Trying to assign value of type '<filename>.gd' to a variable of type ''."
Hello,
I try to write a test for a scene, it have only one node named HealthComponent,
with a script health_component.gd having class_name HealthComponent attached to it.
It work in normal start (run project and run specific project) without error. but in Gut, I got weird result.
It behavior differently when click Run all and Run specific test, and with preload or load for the scene file (.tscn).
when click Run all and load .tsch , I get Trying to assign value of type 'health_component.gd' to a variable of type error can't start.
and in other case, it work (at least it can start), so we have 4 case:
| ..... | run all |
run specific (test_health_component.gd) |
|---|---|---|
preload |
work | work |
load |
got error | work |
# the health_component.gd
extends Node2D
class_name HealthComponent
# <other code commented when run test, but got same result in Gut testing>
# the test_health_component.gd
extends GutTest
class_name TestHealthComponent
# -------------------
# case 1, with load
var health_component_scene: PackedScene = load("res://<path>/health_component.tscn")
# case 2, with preload
var health_component_scene: PackedScene = preload("res://<path>/health_component.tscn")
# -------------------
var health_component: HealthComponent
func before_all():
print('before all in TestHealthComponent')
# TestReferenceLoader.load_reference(self)
func before_each():
print('-----enter gut test run scene-----')
health_component = health_component_scene.instantiate()
print(health_component)
print(health_component is HealthComponent)
print('-----leave gut test run scene-----')
func test_fake_func_to_trigger_before_each():
pass
Does there any hidden process for class_name in Gut?
First time create issue, feel free to tell me if something wrong or lack of information, and thanks in advance !
Godot Engine v4.0.3.stable.official.5222a99f5 Gut 9.0.1 Linux
Some of this sounds familiar. Try without the class_name and without preload. T
here shouldn't be an issue with class_name, the tests for GUT make use of it. Preload triggered something in my memory, but I don't remember what it was.
Let me know what you find. This sounds more like an engine issue than with GUT, but I'd like to understand what is happening.
On Mon, Oct 2, 2023, 11:39 AM XMRHRX @.***> wrote:
Hello,
I try to write a test for a scene, it have only one node named HealthComponent, with a script health_component.gd having class_name HealthComponent attached to it.
It work in normal start (run project and run specific project) without error. but in Gut, I got weird result.
It behavior differently when click Run all and Run specific test, and with preload or load for the scene file (.tscn).
when click Run all and load .tsch , I get Trying to assign value of type ' health_component.gd' to a variable of type error can't start. and in other case, it work (at least it can start), so we have 4 case: ..... run all run specific (test_health_component.gd) preload work work load got error work
the health_component.gdextends Node2Dclass_name HealthComponent# <other code commented when run test, but got same result in Gut testing>
the test_health_component.gdextends GutTestclass_name TestHealthComponent
-------------------# case 1, with loadvar health_component_scene: PackedScene = load("res://
/health_component.tscn") case 2, with preloadvar health_component_scene: PackedScene = preload("res://
/health_component.tscn")# ------------------- var health_component: HealthComponent func before_all(): print('before all in TestHealthComponent')
TestReferenceLoader.load_reference(self)
func before_each(): print('-----enter gut test run scene-----') health_component = health_component_scene.instantiate() print(health_component) print(health_component is HealthComponent) print('-----leave gut test run scene-----') func test_fake_func_to_trigger_before_each(): pass
Does there any hidden process for class_name in Gut?
First time create issue, feel free to tell me if something wrong or lack of information, and thanks in advance !
Godot Engine v4.0.3.stable.official.5222a99f5 Gut 9.0.1 Linux
— Reply to this email directly, view it on GitHub https://github.com/bitwes/Gut/issues/514, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAI2LKETLUBW2ZMJL3YE57DX5LN4RAVCNFSM6AAAAAA5PTZVM6VHI2DSMVQWIX3LMV43ASLTON2WKOZRHEZDEMJWGU4TEMY . You are receiving this because you are subscribed to this thread.Message ID: @.***>
Forget to mention, I also try other case, and see [3] below, might related to what you mentioned.
And see[1], that is why I decide create issue here than godot. ( But not that mean I am sure the problem is from Gut )
[1] Create a new "normal" Scene with Node2D attaching following script to the node:
# this script attach to a node
extends Node2D
var health_component_scene: PackedScene = load("res://features/world_entity/component/health_component.tscn")
var health_component: HealthComponent
func _ready():
in_normal_scene()
func in_normal_scene():
print('-----enter normal run scene-----')
health_component = health_component_scene.instantiate()
print(health_component)
print(health_component is HealthComponent)
print('-----leave normal run scene-----')
And run with "Run Specific Scene" (Instead of "Run Specific Test", so this is default godot functionality).
and it work, output is:
-----enter normal run scene-----
HealthComponent:<Node2D#38503711902>
true
-----leave normal run scene-----
[2] Try to use HealthComponent.new() , instead of load or preload:
extends GutTest
class_name TestHealthComponent
var health_component: HealthComponent
func before_all():
print('before all in TestHealthComponent')
# TestReferenceLoader.load_reference(self)
func before_each():
print('-----enter gut test run scene-----')
health_component = HealthComponent.new()
print(health_component)
print(health_component is HealthComponent)
print('-----leave gut test run scene-----')
func test_fake_func_to_trigger_before_each():
pass
| ..... | run all |
run specific (test_health_component.gd) |
|---|---|---|
<class_name>.new() |
work | work |
it work, and output is:
before all in TestHealthComponent
-----enter gut test run scene-----
<Node2D#52311361000>
true
-----leave gut test run scene-----
The output is different from [1], which got Node2D instead of HealthComponent, but considered be normal behavior of godot.
[3]
Remove the type annotation of var health_component: HealthComponent and with both load and preload:
extends GutTest
class_name TestHealthComponent
# case 1, with load
var health_component_scene: PackedScene = load("res://features/world_entity/component/health_component.tscn")
# case 2, with preload
var health_component_scene: PackedScene = preload("res://features/world_entity/component/health_component.tscn")
var health_component#: HealthComponent
func before_all():
print('before all in TestHealthComponent')
# TestReferenceLoader.load_reference(self)
func before_each():
print('-----enter gut test run scene-----')
health_component = health_component_scene.instantiate()
print(health_component)
print(health_component is HealthComponent)
print('-----leave gut test run scene-----')
func test_fake_func_to_trigger_before_each():
pass
work, but got weird result (notice [result 3]):
| ..... | run all |
run specific (test_health_component.gd) |
|---|---|---|
preload |
[result 1] | [result 2] |
load |
[result 3] | [result 4] |
[result 1] (preload + run all)
<other testing print....>
before all in TestHealthComponent
-----enter gut test run scene-----
HealthComponent:<Node2D#97844726484>
true
-----leave gut test run scene-----
[result 2] (preload + run specific)
before all in TestHealthComponent
-----enter gut test run scene-----
HealthComponent:<Node2D#97844726484>
true
-----leave gut test run scene-----
[result 3] (load + run all)
<other testing print....>
before all in TestCharacterEntity
in before_each
before all in TestHealthComponent
-----enter gut test run scene-----
HealthComponent:<Node2D#97391741641>
false
-----leave gut test run scene-----
[result 4] (load + run specific)
before all in TestHealthComponent
-----enter gut test run scene-----
HealthComponent:<Node2D#52529464823>
true
-----leave gut test run scene-----
I think when running the test with Run All, the class_name is not handled properly.
Maybe the problem located in the difference between the implementation of Run all and Run Specific test?
Something might be worth to mention, how I found these bugs is:
At first , I try to testing my player.tscn, and the @export var health_component: HealthComponent inside player's gdscript got null,
so I try to assign it directly from code (with load, preload), instead selecting export variable in GUI inspector, and resulting in these discovery.
But the strangest thing is, some of the export var in player.tscn resolved and got value, only some got null.
These are all I know for now, and I will try to remove the autoload with the test, and see will it still get error.