code: def test(*paths, subprocess=True, rerun=0, **kwargs):
      """Interface to run tests via pytest compatible with SymPy's test runner.
  
      Explanation
      ===========
  
      Note that a `pytest.ExitCode`, which is an `enum`, is returned. This is
      different to the legacy SymPy test runner which would return a `bool`. If
      all tests sucessfully pass the `pytest.ExitCode.OK` with value `0` is
      returned, whereas the legacy SymPy test runner would return `True`. In any
      other scenario, a non-zero `enum` value is returned, whereas the legacy
      SymPy test runner would return `False`. Users need to, therefore, be careful
      if treating the pytest exit codes as booleans because
      `bool(pytest.ExitCode.OK)` evaluates to `False`, the opposite of legacy
      behaviour.
  
      Examples
      ========
  
      >>> import sympy  # doctest: +SKIP
  
      Run one file:
  
      >>> sympy.test('sympy/core/tests/test_basic.py')  # doctest: +SKIP
      >>> sympy.test('_basic')  # doctest: +SKIP
  
      Run all tests in sympy/functions/ and some particular file:
  
      >>> sympy.test("sympy/core/tests/test_basic.py",
      ...            "sympy/functions")  # doctest: +SKIP
  
      Run all tests in sympy/core and sympy/utilities:
  
      >>> sympy.test("/core", "/util")  # doctest: +SKIP
  
      Run specific test from a file:
  
      >>> sympy.test("sympy/core/tests/test_basic.py",
      ...            kw="test_equality")  # doctest: +SKIP
  
      Run specific test from any file:
  
      >>> sympy.test(kw="subs")  # doctest: +SKIP
  
      Run the tests using the legacy SymPy runner:
  
      >>> sympy.test(use_sympy_runner=True)  # doctest: +SKIP
  
      Note that this option is slated for deprecation in the near future and is
      only currently provided to ensure users have an alternative option while the
      pytest-based runner receives real-world testing.
  
      Parameters
      ==========
      paths : first n positional arguments of strings
          Paths, both partial and absolute, describing which subset(s) of the test
          suite are to be run.
      subprocess : bool, default is True
          Legacy option, is currently ignored.
      rerun : int, default is 0
          Legacy option, is ignored.
      use_sympy_runner : bool or None, default is None
          Temporary option to invoke the legacy SymPy test runner instead of
          `pytest.main`. Will be removed in the near future.
      verbose : bool, default is False
          Sets the verbosity of the pytest output. Using `True` will add the
          `--verbose` option to the pytest call.
      tb : str, 'auto', 'long', 'short', 'line', 'native', or 'no'
          Sets the traceback print mode of pytest using the `--tb` option.
      kw : str
          Only run tests which match the given substring expression. An expression
          is a Python evaluatable expression where all names are substring-matched
          against test names and their parent classes. Example: -k 'test_method or
          test_other' matches all test functions and classes whose name contains
          'test_method' or 'test_other', while -k 'not test_method' matches those
          that don't contain 'test_method' in their names. -k 'not test_method and
          not test_other' will eliminate the matches. Additionally keywords are
          matched to classes and functions containing extra names in their
          'extra_keyword_matches' set, as well as functions which have names
          assigned directly to them. The matching is case-insensitive.
      pdb : bool, default is False
          Start the interactive Python debugger on errors or `KeyboardInterrupt`.
      colors : bool, default is True
          Color terminal output.
      force_colors : bool, default is False
          Legacy option, is ignored.
      sort : bool, default is True
          Run the tests in sorted order. pytest uses a sorted test order by
          default. Requires pytest-randomly.
      seed : int
          Seed to use for random number generation. Requires pytest-randomly.
      timeout : int, default is 0
          Timeout in seconds before dumping the stacks. 0 means no timeout.
          Requires pytest-timeout.
      fail_on_timeout : bool, default is False
          Legacy option, is currently ignored.
      slow : bool, default is False
          Run the subset of tests marked as `slow`.
      enhance_asserts : bool, default is False
          Legacy option, is currently ignored.
      split : string in form `<SPLIT>/<GROUPS>` or None, default is None
          Used to split the tests up. As an example, if `split='2/3' is used then
          only the middle third of tests are run. Requires pytest-split.
      time_balance : bool, default is True
          Legacy option, is currently ignored.
      blacklist : iterable of test paths as strings, default is BLACKLIST_DEFAULT
          Blacklisted test paths are ignored using the `--ignore` option. Paths
          may be partial or absolute. If partial then they are matched against
          all paths in the pytest tests path.
      parallel : bool, default is False
          Parallelize the test running using pytest-xdist. If `True` then pytest
          will automatically detect the number of CPU cores available and use them
          all. Requires pytest-xdist.
      store_durations : bool, False
          Store test durations into the file `.test_durations`. The is used by
          `pytest-split` to help determine more even splits when more than one
          test group is being used. Requires pytest-split.
  
      """
      # NOTE: to be removed alongside SymPy test runner
      if kwargs.get("use_sympy_runner", False):
          kwargs.pop("parallel", False)
          kwargs.pop("store_durations", False)
          kwargs.pop("use_sympy_runner", True)
          if kwargs.get("slow") is None:
              kwargs["slow"] = False
          return test_sympy(*paths, subprocess=True, rerun=0, **kwargs)
  
      pytest_plugin_manager = PytestPluginManager()
      if not pytest_plugin_manager.has_pytest:
          pytest.main()
  
      args = []
      args = update_args_with_rootdir(args)
  
      if kwargs.get("verbose", False):
          args.append("--verbose")
  
      if tb := kwargs.get("tb"):
          args.extend(["--tb", tb])
  
      if kwargs.get("pdb"):
          args.append("--pdb")
  
      if not kwargs.get("colors", True):
          args.extend(["--color", "no"])
  
      if seed := kwargs.get("seed"):
          if not pytest_plugin_manager.has_randomly:
              msg = "`pytest-randomly` plugin required to control random seed."
              raise ModuleNotFoundError(msg)
          args.extend(["--randomly-seed", str(seed)])
  
      if (
          kwargs.get("sort", True)
          and pytest_plugin_manager.has_randomly
      ):
          args.append("--randomly-dont-reorganize")
      elif (
          not kwargs.get("sort", True)
          and not pytest_plugin_manager.has_randomly
      ):
          msg = "`pytest-randomly` plugin required to randomize test order."
          raise ModuleNotFoundError(msg)
  
      if timeout := kwargs.get("timeout", None):
          if not pytest_plugin_manager.has_timeout:
              msg = "`pytest-timeout` plugin required to apply timeout to tests."
              raise ModuleNotFoundError(msg)
          args.extend(["--timeout", str(int(timeout))])
  
      # The use of `bool | None` for the `slow` kwarg allows a configuration file
      # to take precedence if found by pytest, but if one isn't present (e.g. in
      # the case when used with Pyodide) then a user can still explicitly ensure
      # that only the slow tests are run.
      if slow := kwargs.get("slow", None) is not None:
          if slow:
              args.extend(["-m", "slow"])
          else:
              args.extend(["-m", "not slow"])
  
      if (split := kwargs.get("split")) is not None:
          if not pytest_plugin_manager.has_split:
              msg = "`pytest-split` plugin required to run tests as groups."
              raise ModuleNotFoundError(msg)
          match = split_pattern.match(split)
          if not match:
              msg = (
                  "split must be a string of the form a/b where a and b are "
                  "positive nonzero ints"
              )
              raise ValueError(msg)
          group, splits = map(str, match.groups())
          args.extend(["--group", group, "--splits", splits])
          if group > splits:
              msg = (
                  f"cannot have a group number {group} with only {splits} "
                  "splits"
              )
              raise ValueError(msg)
  
      if blacklist := kwargs.get("blacklist", BLACKLIST_DEFAULT):
          for path in blacklist:
              args.extend(["--ignore", make_absolute_path(path)])
  
      if kwargs.get("parallel", False):
          if not pytest_plugin_manager.has_xdist:
              msg = "`pytest-xdist` plugin required to run tests in parallel."
              raise ModuleNotFoundError(msg)
          args.extend(["-n", "auto"])
  
      if kwargs.get("store_durations", False):
          if not pytest_plugin_manager.has_split:
              msg = "`pytest-split` plugin required to store test durations."
              raise ModuleNotFoundError(msg)
          args.append("--store-durations")
  
      if (keywords := kwargs.get("kw")) is not None:
          keywords = tuple(str(kw) for kw in keywords)
      else:
          keywords = ()
  
      args = update_args_with_paths(paths, keywords, args)
      exit_code = pytest.main(args)
      return exit_code
  
imports: import functools
  import importlib.util
  import os
  import pathlib
  import re
  from fnmatch import fnmatch
  from typing import List, Optional, Tuple
  from sympy.testing.runtests import test
label_desc: Use image node_id 5 for calling a global function with example usage: test() and returns: exit_code, test_sympy