code: def test_best_trial(self):
      trials = self.trials
      assert len(trials) == 0
      # It should throw a reasonable error when no valid trials exist.
      trials.insert_trial_doc(create_fake_trial(0, loss=np.NaN))
      trials.refresh()
      with self.assertRaises(AllTrialsFailed):
          assert trials.best_trial is None
  
      # It should work even with some trials with NaN losses.
      trials.insert_trial_doc(create_fake_trial(1, loss=1.0))
      trials.insert_trial_doc(create_fake_trial(2, loss=np.NaN))
      trials.insert_trial_doc(create_fake_trial(3, loss=0.5))
      trials.refresh()
  
      best_trial = trials.best_trial
      self.assertEqual(best_trial["tid"], 3)
  
imports: import copy
  import unittest
  import numpy
  import bson
  from hyperopt.pyll import scope
  from hyperopt.base import JOB_STATE_DONE, JOB_STATE_NEW
  from hyperopt.base import TRIAL_KEYS
  from hyperopt.base import TRIAL_MISC_KEYS
  from hyperopt.base import InvalidTrial
  from hyperopt.base import miscs_to_idxs_vals
  from hyperopt.base import SONify
  from hyperopt.base import STATUS_OK
  from hyperopt.base import Trials
  from hyperopt.base import trials_from_docs
  from hyperopt.exceptions import AllTrialsFailed
label_desc: Use image node_id 4 for calling the TestTrials obj's underlying member method code with example usage: obj.test_best_trial() without return types