prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  Handle "could not import module" errors gracefully
  **Describe the bug**
  Avocado does not handle "could not import module" errors very gracefully, with error messages that are quite cryptic.
  
  **Steps to reproduce**
  Write a valid `avocado-instrumented` test, but with an invalid import.  Example:
  
  ```python
  from avocado import Test
  
  import foo
  
  
  class PassTest(Test):
  
      """
      Example test that passes.
  
      :avocado: tags=fast
      """
  
      def test(self):
          """
          A test simply doesn't have to fail in order to pass
          """
  ```
  
  And run it:
  
  ```
  $ avocado run examples/tests/passtest.py 
  JOB ID     : 3fee9803715e414a16c3dcf1ddb9ff2f6dc6c0bd
  JOB LOG    : /home/cleber/avocado/job-results/job-2022-08-11T10.24-3fee980/job.log
   (1/1) examples/tests/passtest.py:PassTest.test: STARTED
   (1/1) examples/tests/passtest.py:PassTest.test:  ERROR: Test.__init__() got an unexpected keyword argument 'run.results_dir' (0.01 s)
  RESULTS    : PASS 0 | ERROR 1 | FAIL 0 | SKIP 0 | WARN 0 | INTERRUPT 0 | CANCEL 0
  JOB HTML   : /home/cleber/avocado/job-results/job-2022-08-11T10.24-3fee980/results.html
  JOB TIME   : 1.47 s
  ```
  
  **Expected behavior**
  Instead of "unexpected argument..." a more clear error message such as: "failed to import the file containing the test" or something similar. 
  
  **Current behavior**
  
  From original reporter @jnsnow:
  
  ```
  (08/27) tests/protocol.py:Connect.testBadUNIX:  ERROR:
          Test.__init__() got an unexpected keyword argument 'run.results_dir'
          (0.01 s)
  ```
  
  **System information (please complete the following information):**
   - OS: ```LSB Version:	:core-4.1-amd64:core-4.1-noarch:cxx-4.1-amd64:cxx-4.1-noarch:desktop-4.1-amd64:desktop-4.1-noarch:languages-4.1-amd64:languages-4.1-noarch:printing-4.1-amd64:printing-4.1-noarch
  Distributor ID:	Fedora
  Description:	Fedora release 36 (Thirty Six)
  Release:	36
  Codename:	ThirtySix```
   - Avocado version: 5a0c5b2348da450397287a0954e4c335c0d590a9
   - Avocado installation method: git
  
  
  </issue>
  <code>
  [start of avocado/core/utils/loader.py]
  1 import importlib
  2 import inspect
  3 import os
  4 import sys
  5 
  6 from avocado.core import test
  7 from avocado.utils import stacktrace
  8 
  9 
  10 class TestError(test.Test):
  11     """
  12     Generic test error.
  13     """
  14 
  15     def __init__(self, *args, **kwargs):
  16         exception = kwargs.pop("exception")
  17         test.Test.__init__(self, *args, **kwargs)
  18         self.exception = exception
  19 
  20     def test(self):
  21         self.error(self.exception)
  22 
  23 
  24 def load_test(test_factory):
  25     """
  26     Load test from the test factory.
  27 
  28     :param test_factory: a pair of test class and parameters.
  29     :type test_factory: tuple
  30     :return: an instance of :class:`avocado.core.test.Test`.
  31     """
  32     test_class, test_parameters = test_factory
  33     if "modulePath" in test_parameters:
  34         test_path = test_parameters.pop("modulePath")
  35     else:
  36         test_path = None
  37     if isinstance(test_class, str):
  38         module_name = os.path.basename(test_path).split(".")[0]
  39         test_module_dir = os.path.abspath(os.path.dirname(test_path))
  40         # Tests with local dir imports need this
  41         try:
  42             sys.path.insert(0, test_module_dir)
  43             test_module = importlib.import_module(module_name)
  44         except:  # pylint: disable=W0702
  45             # On load_module exception we fake the test class and pass
  46             # the exc_info as parameter to be logged.
  47             test_parameters["methodName"] = "test"
  48             exception = stacktrace.prepare_exc_info(sys.exc_info())
  49             test_parameters["exception"] = exception
  50             return TestError(**test_parameters)
  51         finally:
  52             if test_module_dir in sys.path:
  53                 sys.path.remove(test_module_dir)
  54         for _, obj in inspect.getmembers(test_module):
  55             if (
  56                 inspect.isclass(obj)
  57                 and obj.__name__ == test_class
  58                 and inspect.getmodule(obj) == test_module
  59             ):
  60                 if issubclass(obj, test.Test):
  61                     test_class = obj
  62                     break
  63     if "run.results_dir" in test_parameters:
  64         test_parameters["base_logdir"] = test_parameters.pop("run.results_dir")
  65     test_instance = test_class(**test_parameters)
  66 
  67     return test_instance
  68
  [end of avocado/core/utils/loader.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/avocado/core/utils/loader.py b/avocado/core/utils/loader.py
  --- a/avocado/core/utils/loader.py
  +++ b/avocado/core/utils/loader.py
  @@ -30,6 +30,8 @@
       :return: an instance of :class:`avocado.core.test.Test`.
       """
       test_class, test_parameters = test_factory
  +    if "run.results_dir" in test_parameters:
  +        test_parameters["base_logdir"] = test_parameters.pop("run.results_dir")
       if "modulePath" in test_parameters:
           test_path = test_parameters.pop("modulePath")
       else:
  @@ -60,8 +62,6 @@
                   if issubclass(obj, test.Test):
                       test_class = obj
                       break
  -    if "run.results_dir" in test_parameters:
  -        test_parameters["base_logdir"] = test_parameters.pop("run.results_dir")
       test_instance = test_class(**test_parameters)
   
       return test_instance
  
verification_info: {"golden_diff": "diff --git a/avocado/core/utils/loader.py b/avocado/core/utils/loader.py\n--- a/avocado/core/utils/loader.py\n+++ b/avocado/core/utils/loader.py\n@@ -30,6 +30,8 @@\n     :return: an instance of :class:`avocado.core.test.Test`.\n     \"\"\"\n     test_class, test_parameters = test_factory\n+    if \"run.results_dir\" in test_parameters:\n+        test_parameters[\"base_logdir\"] = test_parameters.pop(\"run.results_dir\")\n     if \"modulePath\" in test_parameters:\n         test_path = test_parameters.pop(\"modulePath\")\n     else:\n@@ -60,8 +62,6 @@\n                 if issubclass(obj, test.Test):\n                     test_class = obj\n                     break\n-    if \"run.results_dir\" in test_parameters:\n-        test_parameters[\"base_logdir\"] = test_parameters.pop(\"run.results_dir\")\n     test_instance = test_class(**test_parameters)\n \n     return test_instance\n", "issue": "Handle \"could not import module\" errors gracefully\n**Describe the bug**\r\nAvocado does not handle \"could not import module\" errors very gracefully, with error messages that are quite cryptic.\r\n\r\n**Steps to reproduce**\r\nWrite a valid `avocado-instrumented` test, but with an invalid import.  Example:\r\n\r\n```python\r\nfrom avocado import Test\r\n\r\nimport foo\r\n\r\n\r\nclass PassTest(Test):\r\n\r\n    \"\"\"\r\n    Example test that passes.\r\n\r\n    :avocado: tags=fast\r\n    \"\"\"\r\n\r\n    def test(self):\r\n        \"\"\"\r\n        A test simply doesn't have to fail in order to pass\r\n        \"\"\"\r\n```\r\n\r\nAnd run it:\r\n\r\n```\r\n$ avocado run examples/tests/passtest.py \r\nJOB ID     : 3fee9803715e414a16c3dcf1ddb9ff2f6dc6c0bd\r\nJOB LOG    : /home/cleber/avocado/job-results/job-2022-08-11T10.24-3fee980/job.log\r\n (1/1) examples/tests/passtest.py:PassTest.test: STARTED\r\n (1/1) examples/tests/passtest.py:PassTest.test:  ERROR: Test.__init__() got an unexpected keyword argument 'run.results_dir' (0.01 s)\r\nRESULTS    : PASS 0 | ERROR 1 | FAIL 0 | SKIP 0 | WARN 0 | INTERRUPT 0 | CANCEL 0\r\nJOB HTML   : /home/cleber/avocado/job-results/job-2022-08-11T10.24-3fee980/results.html\r\nJOB TIME   : 1.47 s\r\n```\r\n\r\n**Expected behavior**\r\nInstead of \"unexpected argument...\" a more clear error message such as: \"failed to import the file containing the test\" or something similar. \r\n\r\n**Current behavior**\r\n\r\nFrom original reporter @jnsnow:\r\n\r\n```\r\n(08/27) tests/protocol.py:Connect.testBadUNIX:  ERROR:\r\n        Test.__init__() got an unexpected keyword argument 'run.results_dir'\r\n        (0.01 s)\r\n```\r\n\r\n**System information (please complete the following information):**\r\n - OS: ```LSB Version:\t:core-4.1-amd64:core-4.1-noarch:cxx-4.1-amd64:cxx-4.1-noarch:desktop-4.1-amd64:desktop-4.1-noarch:languages-4.1-amd64:languages-4.1-noarch:printing-4.1-amd64:printing-4.1-noarch\r\nDistributor ID:\tFedora\r\nDescription:\tFedora release 36 (Thirty Six)\r\nRelease:\t36\r\nCodename:\tThirtySix```\r\n - Avocado version: 5a0c5b2348da450397287a0954e4c335c0d590a9\r\n - Avocado installation method: git\r\n\n", "before_files": [{"content": "import importlib\nimport inspect\nimport os\nimport sys\n\nfrom avocado.core import test\nfrom avocado.utils import stacktrace\n\n\nclass TestError(test.Test):\n    \"\"\"\n    Generic test error.\n    \"\"\"\n\n    def __init__(self, *args, **kwargs):\n        exception = kwargs.pop(\"exception\")\n        test.Test.__init__(self, *args, **kwargs)\n        self.exception = exception\n\n    def test(self):\n        self.error(self.exception)\n\n\ndef load_test(test_factory):\n    \"\"\"\n    Load test from the test factory.\n\n    :param test_factory: a pair of test class and parameters.\n    :type test_factory: tuple\n    :return: an instance of :class:`avocado.core.test.Test`.\n    \"\"\"\n    test_class, test_parameters = test_factory\n    if \"modulePath\" in test_parameters:\n        test_path = test_parameters.pop(\"modulePath\")\n    else:\n        test_path = None\n    if isinstance(test_class, str):\n        module_name = os.path.basename(test_path).split(\".\")[0]\n        test_module_dir = os.path.abspath(os.path.dirname(test_path))\n        # Tests with local dir imports need this\n        try:\n            sys.path.insert(0, test_module_dir)\n            test_module = importlib.import_module(module_name)\n        except:  # pylint: disable=W0702\n            # On load_module exception we fake the test class and pass\n            # the exc_info as parameter to be logged.\n            test_parameters[\"methodName\"] = \"test\"\n            exception = stacktrace.prepare_exc_info(sys.exc_info())\n            test_parameters[\"exception\"] = exception\n            return TestError(**test_parameters)\n        finally:\n            if test_module_dir in sys.path:\n                sys.path.remove(test_module_dir)\n        for _, obj in inspect.getmembers(test_module):\n            if (\n                inspect.isclass(obj)\n                and obj.__name__ == test_class\n                and inspect.getmodule(obj) == test_module\n            ):\n                if issubclass(obj, test.Test):\n                    test_class = obj\n                    break\n    if \"run.results_dir\" in test_parameters:\n        test_parameters[\"base_logdir\"] = test_parameters.pop(\"run.results_dir\")\n    test_instance = test_class(**test_parameters)\n\n    return test_instance\n", "path": "avocado/core/utils/loader.py"}]}