From 278364865ec6ab17497015f3980a7e5d3e64c697 Mon Sep 17 00:00:00 2001 From: Beraldo Leal Date: Mon, 17 Aug 2020 13:56:22 -0300 Subject: [PATCH] nrunner: fix path when loading python unit tests The current runner loader/discovery method is a custom build and finds modules/tests recursively on the current folder. With the new runner, part of the python unittest discover was delegated to 'loadTestsFromName()' on the standard library that uses a different logic for this (assumes that we need to import the test). Because of that we need 1) create a custom base loader here, or 2) prepend the path with the current dir so loadTestsFromName will return a valid test suite. This might not be the perfect solution but was a hot-fix found for LTS. Fixes #3851 Reference: https://docs.python.org/3/library/unittest.html#unittest.TestLoader.loadTestsFromName Signed-off-by: Beraldo Leal --- avocado/core/nrunner.py | 1 + 1 file changed, 1 insertion(+) diff --git a/avocado/core/nrunner.py b/avocado/core/nrunner.py index 07f7d32d..23f90fbf 100755 --- a/avocado/core/nrunner.py +++ b/avocado/core/nrunner.py @@ -468,6 +468,7 @@ class PythonUnittestRunner(BaseRunner): @staticmethod def _run_unittest(uri, queue): + sys.path.insert(0, ".") stream = io.StringIO() unittest_name = PythonUnittestRunner._uri_to_unittest_name(uri) suite = unittest.TestLoader().loadTestsFromName(unittest_name) -- GitLab