class_docstr: Generic template for memory leak tests.
code: def test_for_memory_leak(
      self, name_for_dumped_files: Text, tmp_path: Path
  ) -> None:
      # Run as separate process to avoid other things affecting the memory usage.
      # Unfortunately `memory-profiler` doesn't work properly with
      # `multiprocessing.Process` as it can't handle the process exit
      process = subprocess.Popen(
          [
              sys.executable,
              "-c",
              (
                  f"from {__name__} import {self.__class__.__name__}; "
                  f"t = {self.__class__.__name__}();"
                  f"t.function_to_profile()"
              ),
          ],
          # Force TensorFlow to use CPU so we can track the memory usage
          env={"CUDA_VISIBLE_DEVICES": "-1"},
      )
  
      # Wait until process is running to avoid race conditions with the memory
      # profiling
      while not psutil.pid_exists(process.pid):
          time.sleep(0.01)
  
      results = memory_profiler.memory_usage(
          process,
          interval=PROFILING_INTERVAL,
          include_children=True,
          timestamps=True,
      )
  
      # `memory-profiler` sometimes adds `None` values at the end which we don't need
      results = [
          memory_timestamp
          for memory_timestamp in results
          if memory_timestamp is not None
      ]
  
      if WRITE_RESULTS_TO_DISK:
          self._write_results(name_for_dumped_files, results)
  
      max_memory_usage = max(
          results, key=lambda memory_time: memory_time[0]
      )[0]
      assert max_memory_usage < self.max_memory_threshold_mb
  
imports: import abc
  import json
  import subprocess
  import sys
  import time
  from pathlib import Path
  from typing import Text, List, Tuple, Optional, Union
  import memory_profiler
  import psutil
  import pytest
  import rasa
  import rasa.shared.utils.io
  from rasa.utils.common import TempDirectoryPath, get_temp_dir_name
label_desc: Use image node_id 4 for calling the MemoryLeakTest obj's underlying member method code with example usage: obj.test_for_memory_leak(name_for_dumped_files, tmp_path) without return types