code: def function_scope_seed(request):
      """A function scope fixture that manages rng seeds.
  
      This fixture automatically initializes the python, numpy and mxnet random
      number generators randomly on every test run.
  
      def test_ok_with_random_data():
          ...
  
      To fix the seed used for a test case mark the test function with the
      desired seed:
  
      @pytest.mark.seed(1)
      def test_not_ok_with_random_data():
          '''This testcase actually works.'''
          assert 17 == random.randint(0, 100)
  
      When a test fails, the fixture outputs the seed used. The user can then set
      the environment variable MXNET_TEST_SEED to the value reported, then rerun
      the test with:
  
          pytest --verbose -s <test_module_name.py> -k <failing_test>
  
      To run a test repeatedly, install pytest-repeat and add the --count argument:
  
          pip install pytest-repeat
          pytest --verbose -s <test_module_name.py> -k <failing_test> --count 1000
  
      """
  
      seed = request.node.get_closest_marker("seed")
      env_seed_str = os.getenv("MXNET_TEST_SEED")
  
      if seed is not None:
          seed = seed.args[0]
          assert isinstance(seed, int)
      elif env_seed_str is not None:
          seed = int(env_seed_str)
      else:
          seed = np.random.randint(0, np.iinfo(np.int32).max)
  
      post_test_state = np.random.get_state()
      np.random.seed(seed)
      mx.random.seed(seed)
      random.seed(seed)
  
      seed_message = (
          "np/mx/python random seeds are set to "
          "{}, use MXNET_TEST_SEED={} to reproduce."
      )
      seed_message = seed_message.format(seed, seed)
  
      # Always log seed on DEBUG log level. This makes sure we can find out the
      # value of the seed even if the test case causes a segfault and subsequent
      # teardown code is not run.
      logging.debug(seed_message)
  
      yield  # run the test
  
      if request.node.rep_setup.failed:
          logging.info(
              "Setting up a test failed: {}", request.node.nodeid
          )
      elif request.node.rep_call.outcome == "failed":
          # Either request.node.rep_setup.failed or request.node.rep_setup.passed
          # should be True
          assert request.node.rep_setup.passed
          # On failure also log seed on INFO log level
          logging.info(seed_message)
  
      np.random.set_state(post_test_state)
  
file_path: gluon-nlp/conftest.py
imports: import logging
  import os
  import random
  import numpy
  import mxnet
  import gluonnlp
  import pytest
label_desc: Use image node_id 5 for calling a global function with example usage: function_scope_seed(request) without return types