lkml.org 
[lkml]   [2020]   [Nov]   [30]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
Subject[PATCH 2/5] kunit: tool: fix unit test so it can run from non-root dir
From
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@google.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
\
 
 \ /
  Last update: 2020-12-01 00:36    [W:1.509 / U:0.084 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site