code: def check_python_eval(cmd, path):
      ds = Dataset(path).create()
      res = ds.foreach_dataset(cmd, cmd_type="eval")
      eq_(len(res), 1)
      expected_variables = {"ds", "pwd", "refds"}
      eq_(
          expected_variables.intersection(res[0]["result"]),
          expected_variables,
      )
      # besides expected, there could be few more ATM, +5 arbitrarily just to test
      # that we are not leaking too much
      assert_greater(len(expected_variables) + 5, len(res[0]["result"]))
  
file_path: datalad/datalad/local/tests/test_foreach_dataset.py
imports: import os.path
  import sys
  from pathlib import Path
  import pytest
  from datalad.api import create
  from datalad.distribution.dataset import Dataset
  from datalad.tests.utils_pytest import assert_false, assert_greater, assert_in, assert_not_in, assert_status, eq_, get_deeply_nested_structure, ok_clean_git, swallow_outputs, with_tempfile
label_desc: Use image node_id 4 for calling a global function with example usage: check_python_eval(cmd, path) without return types