From 5e32ecccba2a1c086c8746d65b9fa9f79e8f2370 Mon Sep 17 00:00:00 2001 From: Sergei Silnov Date: Fri, 27 May 2022 10:41:48 +0200 Subject: [PATCH] Tools: Make idf.py tests independent on extra extensions --- tools/test_idf_py/test_idf_py.py | 42 +++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/tools/test_idf_py/test_idf_py.py b/tools/test_idf_py/test_idf_py.py index 4049a141a0..8ed6b32174 100755 --- a/tools/test_idf_py/test_idf_py.py +++ b/tools/test_idf_py/test_idf_py.py @@ -17,7 +17,7 @@ import os import subprocess import sys -import unittest +from unittest import TestCase, main try: from StringIO import StringIO @@ -36,7 +36,17 @@ extension_path = os.path.join(current_dir, 'test_idf_extensions', 'test_ext') link_path = os.path.join(current_dir, '..', 'idf_py_actions', 'test_ext') -class TestExtensions(unittest.TestCase): +class TestWithoutExtensions(TestCase): + def setUp(self): + self.initial_env = dict(os.environ) + os.environ['IDF_COMPONENT_MANAGER'] = '0' + os.environ['IDF_EXTRA_ACTIONS_PATH'] = '' + + def tearDown(self): + os.environ = self.initial_env + + +class TestExtensions(TestWithoutExtensions): def test_extension_loading(self): try: os.symlink(extension_path, link_path) @@ -78,7 +88,7 @@ class TestExtensions(unittest.TestCase): os.remove(link_path) -class TestDependencyManagement(unittest.TestCase): +class TestDependencyManagement(TestWithoutExtensions): def test_dependencies(self): result = idf.init_cli()( args=['--dry-run', 'flash'], @@ -129,7 +139,7 @@ class TestDependencyManagement(unittest.TestCase): 'WARNING: Command "clean" is found in the list of commands more than once.', capturedOutput.getvalue()) -class TestVerboseFlag(unittest.TestCase): +class TestVerboseFlag(TestWithoutExtensions): def test_verbose_messages(self): output = subprocess.check_output( [ @@ -155,7 +165,7 @@ class TestVerboseFlag(unittest.TestCase): self.assertNotIn('Verbose mode on', output) -class TestGlobalAndSubcommandParameters(unittest.TestCase): +class TestGlobalAndSubcommandParameters(TestWithoutExtensions): def test_set_twice_same_value(self): """Can set -D twice: globally and for subcommand if values are the same""" @@ -174,21 +184,24 @@ class TestGlobalAndSubcommandParameters(unittest.TestCase): ) -class TestDeprecations(unittest.TestCase): +class TestDeprecations(TestWithoutExtensions): def test_exit_with_error_for_subcommand(self): try: - subprocess.check_output([sys.executable, idf_py_path, '-C%s' % current_dir, 'test-2'], env=os.environ, - stderr=subprocess.STDOUT) + subprocess.check_output( + [sys.executable, idf_py_path, '-C%s' % current_dir, 'test-2'], env=os.environ, stderr=subprocess.STDOUT) except subprocess.CalledProcessError as e: self.assertIn('Error: Command "test-2" is deprecated and was removed.', e.output.decode('utf-8', 'ignore')) def test_exit_with_error_for_option(self): try: - subprocess.check_output([sys.executable, idf_py_path, '-C%s' % current_dir, '--test-5=asdf'], - env=os.environ, stderr=subprocess.STDOUT) + subprocess.check_output( + [sys.executable, idf_py_path, '-C%s' % current_dir, '--test-5=asdf'], + env=os.environ, + stderr=subprocess.STDOUT) except subprocess.CalledProcessError as e: - self.assertIn('Error: Option "test_5" is deprecated since v2.0 and was removed in v3.0.', - e.output.decode('utf-8', 'ignore')) + self.assertIn( + 'Error: Option "test_5" is deprecated since v2.0 and was removed in v3.0.', + e.output.decode('utf-8', 'ignore')) def test_deprecation_messages(self): output = subprocess.check_output( @@ -206,7 +219,8 @@ class TestDeprecations(unittest.TestCase): 'ta', 'test-1', ], - env=os.environ, stderr=subprocess.STDOUT).decode('utf-8', 'ignore') + env=os.environ, + stderr=subprocess.STDOUT).decode('utf-8', 'ignore') self.assertIn('Warning: Option "test_sub_1" is deprecated and will be removed in future versions.', output) self.assertIn( @@ -222,4 +236,4 @@ class TestDeprecations(unittest.TestCase): if __name__ == '__main__': - unittest.main() + main()