Exemple #1
0
def check_memory_leak(request):
    if request.node.get_marker("ignore_leaks"):
        yield
    else:
        dynamic_mem_start = OS.get_dynamic_memory_usage()
        static_mem_start = OS.get_static_memory_usage()

        yield

        static_mem_end = OS.get_static_memory_usage()
        dynamic_mem_end = OS.get_dynamic_memory_usage()

        static_leak = static_mem_end - static_mem_start
        dynamic_leak = dynamic_mem_end - dynamic_mem_start
        assert static_leak == 0
        assert dynamic_leak == 0
Exemple #2
0
    def _ready(self):
        ok = True
        # Children _ready should have been called before us
        try:
            ok &= self.check_accessor_ok("access_from_gdscript")
            ok &= self.check_accessor_ok("access_from_python")
            ok &= self.check_global_ok("global_gd")
            ok &= self.check_global_ok("global_py")
        except Exception as exc:
            print("Unexpected error !")
            traceback.print_exc()
            ok = False

        if not ok:
            OS.set_exit_code(1)
        # Exit godot
        self.get_tree().quit()
Exemple #3
0
 def _ready(self):
     set_current_node(self)
     # Retrieve command line arguments passed through --pytest=...
     prefix = "--pytest="
     pytest_args = []
     for gdarg in OS.get_cmdline_args():
         arg = str(gdarg)
         if arg.startswith(prefix):
             pytest_args += arg[len(prefix):].split(",")
     if all(arg.startswith("-") for arg in pytest_args):
         # Filter to avoid scanning `plugins` and `lib` directories
         pytest_args += [x for x in os.listdir() if x.startswith("test_")]
     # Run tests here
     print(f"running `pytest {' '.join(pytest_args)}`")
     if pytest.main(pytest_args):
         OS.set_exit_code(1)
     # Exit godot
     self.get_tree().quit()
Exemple #4
0
def environment_factory():
    # Environment objects are stubbed on headless server, hence
    # their corresponding RID is always the same default value
    if OS.has_feature("Server"):
        pytest.skip("Not available on headless Godot")

    def _factory():
        return Environment()

    return _factory
Exemple #5
0
 def run_tests(self):
     global root_node
     root_node = self
     # Retrieve command line arguments passed through --pytest=...
     prefix = "--pytest="
     pytest_args = []
     for gdarg in OS.get_cmdline_args():
         arg = str(gdarg)
         if arg.startswith(prefix):
             pytest_args += arg[len(prefix):].split(",")
     if all(arg.startswith("-") for arg in pytest_args):
         # Filter to avoid scanning `plugins` and `lib` directories
         pytest_args += [x for x in os.listdir() if x.startswith("test_")]
     # Run tests here
     print(f"running `pytest {' '.join(pytest_args)}`")
     return pytest.main(pytest_args)
def test_inheritance(generate_obj):
    node = generate_obj(Node)

    # CanvasItem is a direct subclass of Node
    canvas_item = generate_obj(CanvasItem)
    assert isinstance(node, Object)
    assert isinstance(canvas_item, Object)
    assert isinstance(canvas_item, Node)

    # TODO: headless server end up with a static memory leak
    # when instanciating a Node2D...
    if not OS.has_feature("Server"):
        # Node2D is a grand child subclass of Node
        node2d = generate_obj(Node2D)
        assert isinstance(node, Object)
        assert isinstance(node2d, Object)
        assert isinstance(node2d, Node)