code: def test_cont_fit(distname, arg, method):
      if distname in failing_fits[method]:
          # Skip failing fits unless overridden
          try:
              xfail = not int(os.environ["SCIPY_XFAIL"])
          except Exception:
              xfail = True
          if xfail:
              msg = "Fitting %s doesn't work reliably yet" % distname
              msg += (
                  " [Set environment variable SCIPY_XFAIL=1 to run this"
                  " test nevertheless.]"
              )
              pytest.xfail(msg)
  
      distfn = getattr(stats, distname)
  
      truearg = np.hstack([arg, [0.0, 1.0]])
      diffthreshold = np.max(
          np.vstack(
              [
                  truearg * thresh_percent,
                  np.full(distfn.numargs + 2, thresh_min),
              ]
          ),
          0,
      )
  
      for fit_size in fit_sizes:
          # Note that if a fit succeeds, the other fit_sizes are skipped
          np.random.seed(1234)
  
          with np.errstate(all="ignore"):
              rvs = distfn.rvs(size=fit_size, *arg)
              if method == "MLE" and distfn.name in mle_use_floc0:
                  kwds = {"floc": 0}
              else:
                  kwds = {}
              # start with default values
              est = distfn.fit(rvs, method=method, **kwds)
              if method == "MLE":
                  # Trivial test of the use of CensoredData.  The fit() method
                  # will check that data contains no actual censored data, and
                  # do a regular uncensored fit.
                  data1 = stats.CensoredData(rvs)
                  est1 = distfn.fit(data1, **kwds)
                  msg = (
                      "Different results fitting uncensored data wrapped as"
                      f" CensoredData: {distfn.name}: est={est} est1={est1}"
                  )
                  assert_allclose(est1, est, rtol=1e-10, err_msg=msg)
              if (
                  method == "MLE"
                  and distname not in fail_interval_censored
              ):
                  # Convert the first `nic` values in rvs to interval-censored
                  # values. The interval is small, so est2 should be close to
                  # est.
                  nic = 15
                  interval = np.column_stack((rvs, rvs))
                  interval[:nic, 0] *= 0.99
                  interval[:nic, 1] *= 1.01
                  interval.sort(axis=1)
                  data2 = stats.CensoredData(interval=interval)
                  est2 = distfn.fit(data2, **kwds)
                  msg = (
                      "Different results fitting interval-censored"
                      f" data: {distfn.name}: est={est} est2={est2}"
                  )
                  assert_allclose(est2, est, rtol=0.05, err_msg=msg)
  
          diff = est - truearg
  
          # threshold for location
          diffthreshold[-2] = np.max(
              [np.abs(rvs.mean()) * thresh_percent, thresh_min]
          )
  
          if np.any(np.isnan(est)):
              raise AssertionError("nan returned in fit")
          else:
              if np.all(np.abs(diff) <= diffthreshold):
                  break
      else:
          txt = "parameter: %s\n" % str(truearg)
          txt += "estimated: %s\n" % str(est)
          txt += "diff     : %s\n" % str(diff)
          raise AssertionError(
              "fit not very good in %s\n" % distfn.name + txt
          )
  
imports: import os
  import numpy
  import numpy.testing
  from numpy.testing import assert_allclose, assert_equal
  import pytest
  from scipy import stats
  from scipy.optimize import differential_evolution
  from .test_continuous_basic import distcont
  from scipy.stats._distn_infrastructure import FitError
  from scipy.stats._distr_params import distdiscrete
  from scipy.stats import goodness_of_fit
label_desc: Use image node_id 2 for calling a global function with example usage: test_cont_fit(distname, arg, method) without return types