[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20201130233242.78413-2-dlatypov@google.com>
Date: Mon, 30 Nov 2020 15:32:39 -0800
From: Daniel Latypov <dlatypov@...gle.com>
To: davidgow@...gle.com
Cc: brendanhiggins@...gle.com, linux-kernel@...r.kernel.org,
linux-kselftest@...r.kernel.org, skhan@...uxfoundation.org,
Daniel Latypov <dlatypov@...gle.com>
Subject: [PATCH 2/5] kunit: tool: fix unit test so it can run from non-root dir
get_absolute_path() makes an attempt to allow for this.
But that doesn't work as soon as os.chdir() gets called.
So make it so that os.chdir() does nothing to avoid this.
Note: mock.patch.object() doesn't seem to work in setUpModule(), hence
the introduction of a new base class instead.
Fixes: 5578d008d9e0 ("kunit: tool: fix running kunit_tool from outside kernel tree")
Signed-off-by: Daniel Latypov <dlatypov@...gle.com>
---
tools/testing/kunit/kunit_tool_test.py | 15 +++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)
diff --git a/tools/testing/kunit/kunit_tool_test.py b/tools/testing/kunit/kunit_tool_test.py
index 3fbe1acd531a..9f1f1e1b772a 100755
--- a/tools/testing/kunit/kunit_tool_test.py
+++ b/tools/testing/kunit/kunit_tool_test.py
@@ -32,7 +32,13 @@ def tearDownModule():
def get_absolute_path(path):
return os.path.join(os.path.dirname(__file__), path)
-class KconfigTest(unittest.TestCase):
+class KUnitTest(unittest.TestCase):
+ """Contains common setup, like stopping main() from calling chdir."""
+ def setUp(self):
+ mock.patch.object(os, 'chdir').start()
+ self.addCleanup(mock.patch.stopall)
+
+class KconfigTest(KUnitTest):
def test_is_subset_of(self):
kconfig0 = kunit_config.Kconfig()
@@ -88,7 +94,7 @@ class KconfigTest(unittest.TestCase):
self.assertEqual(actual_kconfig.entries(),
expected_kconfig.entries())
-class KUnitParserTest(unittest.TestCase):
+class KUnitParserTest(KUnitTest):
def assertContains(self, needle, haystack):
for line in haystack:
@@ -250,7 +256,7 @@ class KUnitParserTest(unittest.TestCase):
result.status)
self.assertEqual('kunit-resource-test', result.suites[0].name)
-class KUnitJsonTest(unittest.TestCase):
+class KUnitJsonTest(KUnitTest):
def _json_for(self, log_file):
with(open(get_absolute_path(log_file))) as file:
@@ -285,8 +291,9 @@ class StrContains(str):
def __eq__(self, other):
return self in other
-class KUnitMainTest(unittest.TestCase):
+class KUnitMainTest(KUnitTest):
def setUp(self):
+ super().setUp()
path = get_absolute_path('test_data/test_is_test_passed-all_passed.log')
with open(path) as file:
all_passed_log = file.readlines()
--
2.29.2.454.gaff20da3a2-goog
Powered by blists - more mailing lists