From 2840628443584c18a2a016ac3419612c142c2e36 Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Thu, 1 Dec 2022 23:23:48 +0100 Subject: [PATCH] Improved tests #129 --- unittests/unittests_cli/abc/__init__.py | 0 .../unittests_cli/abc/command_test_case.py | 35 +++++++++++++++++++ unittests/unittests_cli/add_test_case.py | 20 +++-------- unittests/unittests_cli/build_test_case.py | 16 +++------ unittests/unittests_cli/cli_test_suite.py | 5 +++ unittests/unittests_cli/constants.py | 2 +- unittests/unittests_cli/custom_test_case.py | 4 +-- unittests/unittests_cli/generate_test_case.py | 5 +-- unittests/unittests_cli/install_test_case.py | 14 +++----- unittests/unittests_cli/new_test_case.py | 14 +++----- unittests/unittests_cli/publish_test_case.py | 14 +++----- unittests/unittests_cli/remove_test_case.py | 7 ++-- unittests/unittests_cli/run_test_case.py | 19 +++------- unittests/unittests_cli/start_test_case.py | 14 +++----- .../unittests_cli/uninstall_test_case.py | 16 +++------ unittests/unittests_cli/update_test_case.py | 34 +++++++----------- unittests/unittests_cli/version_test_case.py | 7 ++-- unittests/unittests_shared/cli_commands.py | 4 ++- .../translation_test_suite.py | 26 -------------- 19 files changed, 103 insertions(+), 153 deletions(-) create mode 100644 unittests/unittests_cli/abc/__init__.py create mode 100644 unittests/unittests_cli/abc/command_test_case.py diff --git a/unittests/unittests_cli/abc/__init__.py b/unittests/unittests_cli/abc/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/unittests/unittests_cli/abc/command_test_case.py b/unittests/unittests_cli/abc/command_test_case.py new file mode 100644 index 00000000..3b609cab --- /dev/null +++ b/unittests/unittests_cli/abc/command_test_case.py @@ -0,0 +1,35 @@ +import os +import shutil +import traceback +import unittest + +from unittests_cli.constants import PLAYGROUND_PATH + + +class CommandTestCase(unittest.TestCase): + + def __init__(self, method_name: str): + unittest.TestCase.__init__(self, method_name) + + @classmethod + def setUpClass(cls): + + try: + if os.path.exists(PLAYGROUND_PATH): + shutil.rmtree(os.path.abspath(os.path.join(PLAYGROUND_PATH))) + + os.makedirs(PLAYGROUND_PATH) + os.chdir(PLAYGROUND_PATH) + except Exception as e: + print(f'Setup of {__name__} failed: {traceback.format_exc()}') + + def setUp(self): + os.chdir(PLAYGROUND_PATH) + + @classmethod + def tearDownClass(cls): + try: + if os.path.exists(PLAYGROUND_PATH): + shutil.rmtree(os.path.abspath(os.path.join(PLAYGROUND_PATH))) + except Exception as e: + print(f'Cleanup of {__name__} failed: {traceback.format_exc()}') diff --git a/unittests/unittests_cli/add_test_case.py b/unittests/unittests_cli/add_test_case.py index d1b64503..18efb1bd 100644 --- a/unittests/unittests_cli/add_test_case.py +++ b/unittests/unittests_cli/add_test_case.py @@ -1,18 +1,16 @@ import json import os -import shutil -import unittest from cpl_core.utils import String - +from unittests_cli.abc.command_test_case import CommandTestCase from unittests_cli.constants import PLAYGROUND_PATH from unittests_shared.cli_commands import CLICommands -class AddTestCase(unittest.TestCase): +class AddTestCase(CommandTestCase): - def __init__(self, methodName: str): - unittest.TestCase.__init__(self, methodName) + def __init__(self, method_name: str): + CommandTestCase.__init__(self, method_name) self._source = 'add-test-project' self._target = 'add-test-library' self._project_file = f'src/{String.convert_to_snake_case(self._source)}/{self._source}.json' @@ -26,22 +24,12 @@ class AddTestCase(unittest.TestCase): return project_json def setUp(self): - if not os.path.exists(PLAYGROUND_PATH): - os.makedirs(PLAYGROUND_PATH) - os.chdir(PLAYGROUND_PATH) # create projects CLICommands.new('console', self._source, '--ab', '--s') os.chdir(os.path.join(os.getcwd(), self._source)) CLICommands.new('console', self._target, '--ab', '--s') - def cleanUp(self): - # remove projects - if not os.path.exists(os.path.abspath(os.path.join(PLAYGROUND_PATH, self._source))): - return - - shutil.rmtree(os.path.abspath(os.path.join(PLAYGROUND_PATH, self._source))) - def test_add(self): CLICommands.add(self._source, self._target) settings = self._get_project_settings() diff --git a/unittests/unittests_cli/build_test_case.py b/unittests/unittests_cli/build_test_case.py index d01de06f..a0117712 100644 --- a/unittests/unittests_cli/build_test_case.py +++ b/unittests/unittests_cli/build_test_case.py @@ -2,18 +2,17 @@ import filecmp import json import os import shutil -import unittest from cpl_core.utils import String - +from unittests_cli.abc.command_test_case import CommandTestCase from unittests_cli.constants import PLAYGROUND_PATH from unittests_shared.cli_commands import CLICommands -class BuildTestCase(unittest.TestCase): +class BuildTestCase(CommandTestCase): - def __init__(self, methodName: str): - unittest.TestCase.__init__(self, methodName) + def __init__(self, method_name: str): + CommandTestCase.__init__(self, method_name) self._source = 'build-test-source' self._project_file = f'src/{String.convert_to_snake_case(self._source)}/{self._source}.json' @@ -39,13 +38,6 @@ class BuildTestCase(unittest.TestCase): CLICommands.new('console', self._source, '--ab', '--s') os.chdir(os.path.join(os.getcwd(), self._source)) - def cleanUp(self): - # remove projects - if not os.path.exists(os.path.abspath(os.path.join(PLAYGROUND_PATH, self._source))): - return - - shutil.rmtree(os.path.abspath(os.path.join(PLAYGROUND_PATH, self._source))) - def _are_dir_trees_equal(self, dir1, dir2): """ found at https://stackoverflow.com/questions/4187564/recursively-compare-two-directories-to-ensure-they-have-the-same-files-and-subdi diff --git a/unittests/unittests_cli/cli_test_suite.py b/unittests/unittests_cli/cli_test_suite.py index 228fa366..9ca8b469 100644 --- a/unittests/unittests_cli/cli_test_suite.py +++ b/unittests/unittests_cli/cli_test_suite.py @@ -76,3 +76,8 @@ class CLITestSuite(unittest.TestSuite): self._setup() self._result = super().run(*args) self._cleanup() + + +if __name__ == "__main__": + runner = unittest.TextTestRunner() + runner.run(CLITestSuite()) diff --git a/unittests/unittests_cli/constants.py b/unittests/unittests_cli/constants.py index 13986be9..c8318dab 100644 --- a/unittests/unittests_cli/constants.py +++ b/unittests/unittests_cli/constants.py @@ -6,4 +6,4 @@ if not os.getcwd().endswith('unittests'): PLAYGROUND_PATH = os.path.abspath(os.path.join(os.getcwd(), f'{base}test_cli_playground')) TRANSLATION_PATH = os.path.abspath(os.path.join(os.getcwd(), f'{base}unittests_translation')) -CLI_PATH = os.path.abspath(os.path.join(os.getcwd(), f'../../src/cpl_cli/main.py')) +CLI_PATH = os.path.abspath(os.path.join(os.getcwd(), f'{base}../src/cpl_cli/main.py')) diff --git a/unittests/unittests_cli/custom_test_case.py b/unittests/unittests_cli/custom_test_case.py index db59be7d..9088cc44 100644 --- a/unittests/unittests_cli/custom_test_case.py +++ b/unittests/unittests_cli/custom_test_case.py @@ -1,7 +1,7 @@ -import unittest +from unittests_cli.abc.command_test_case import CommandTestCase -class CustomTestCase(unittest.TestCase): +class CustomTestCase(CommandTestCase): def setUp(self): pass diff --git a/unittests/unittests_cli/generate_test_case.py b/unittests/unittests_cli/generate_test_case.py index c53f28d5..cba7d8a7 100644 --- a/unittests/unittests_cli/generate_test_case.py +++ b/unittests/unittests_cli/generate_test_case.py @@ -1,17 +1,18 @@ import os.path -import unittest from cpl_core.utils import String +from unittests_cli.abc.command_test_case import CommandTestCase from unittests_cli.constants import PLAYGROUND_PATH from unittests_shared.cli_commands import CLICommands -class GenerateTestCase(unittest.TestCase): +class GenerateTestCase(CommandTestCase): _project = 'test-console' _t_path = 'test' @classmethod def setUpClass(cls): + CommandTestCase.setUpClass() CLICommands.new('console', cls._project, '--ab', '--s', '--venv') def setUp(self): diff --git a/unittests/unittests_cli/install_test_case.py b/unittests/unittests_cli/install_test_case.py index 516a44e4..eaa2a367 100644 --- a/unittests/unittests_cli/install_test_case.py +++ b/unittests/unittests_cli/install_test_case.py @@ -6,14 +6,15 @@ import sys import unittest from cpl_core.utils import String +from unittests_cli.abc.command_test_case import CommandTestCase from unittests_cli.constants import PLAYGROUND_PATH from unittests_shared.cli_commands import CLICommands -class InstallTestCase(unittest.TestCase): +class InstallTestCase(CommandTestCase): - def __init__(self, methodName: str): - unittest.TestCase.__init__(self, methodName) + def __init__(self, method_name: str): + CommandTestCase.__init__(self, method_name) self._source = 'install-test-source' self._project_file = f'src/{String.convert_to_snake_case(self._source)}/{self._source}.json' @@ -39,13 +40,6 @@ class InstallTestCase(unittest.TestCase): CLICommands.new('console', self._source, '--ab', '--s') os.chdir(os.path.join(os.getcwd(), self._source)) - def cleanUp(self): - # remove projects - if not os.path.exists(os.path.abspath(os.path.join(PLAYGROUND_PATH, self._source))): - return - - shutil.rmtree(os.path.abspath(os.path.join(PLAYGROUND_PATH, self._source))) - def _get_installed_packages(self) -> dict: reqs = subprocess.check_output([sys.executable, '-m', 'pip', 'freeze']) return dict([tuple(r.decode().split('==')) for r in reqs.split()]) diff --git a/unittests/unittests_cli/new_test_case.py b/unittests/unittests_cli/new_test_case.py index 5d0eb0a3..21191333 100644 --- a/unittests/unittests_cli/new_test_case.py +++ b/unittests/unittests_cli/new_test_case.py @@ -1,19 +1,16 @@ import json import os -import unittest from cpl_core.utils import String +from unittests_cli.abc.command_test_case import CommandTestCase from unittests_cli.constants import PLAYGROUND_PATH from unittests_shared.cli_commands import CLICommands -class NewTestCase(unittest.TestCase): +class NewTestCase(CommandTestCase): - def setUp(self): - if not os.path.exists(PLAYGROUND_PATH): - os.makedirs(PLAYGROUND_PATH) - - os.chdir(PLAYGROUND_PATH) + def __init__(self, method_name: str): + CommandTestCase.__init__(self, method_name) def _test_project(self, project_type: str, name: str, *args, test_venv=False, without_ws=False): CLICommands.new(project_type, name, *args) @@ -73,7 +70,6 @@ class NewTestCase(unittest.TestCase): project_path = os.path.abspath(os.path.join(PLAYGROUND_PATH, workspace_name, base, String.convert_to_snake_case(name))) self.assertTrue(os.path.exists(project_path)) self.assertTrue(os.path.join(project_path, f'{name}.json')) - os.chdir(os.path.abspath(os.path.join(os.getcwd(), '../'))) def _test_sub_directory_project(self, project_type: str, directory: str, name: str, workspace_name: str, *args): os.chdir(os.path.abspath(os.path.join(os.getcwd(), workspace_name))) @@ -99,8 +95,6 @@ class NewTestCase(unittest.TestCase): self.assertEqual(build_settings['Main'], f'{String.convert_to_snake_case(name)}.main') self.assertEqual(build_settings['EntryPoint'], name) - os.chdir(os.path.abspath(os.path.join(os.getcwd(), '../'))) - def test_console(self): self._test_project('console', 'test-console', '--ab', '--s', '--venv', test_venv=True) diff --git a/unittests/unittests_cli/publish_test_case.py b/unittests/unittests_cli/publish_test_case.py index 141e374e..9992626b 100644 --- a/unittests/unittests_cli/publish_test_case.py +++ b/unittests/unittests_cli/publish_test_case.py @@ -5,15 +5,16 @@ import shutil import unittest from cpl_core.utils import String +from unittests_cli.abc.command_test_case import CommandTestCase from unittests_cli.constants import PLAYGROUND_PATH from unittests_shared.cli_commands import CLICommands -class PublishTestCase(unittest.TestCase): +class PublishTestCase(CommandTestCase): - def __init__(self, methodName: str): - unittest.TestCase.__init__(self, methodName) + def __init__(self, method_name: str): + CommandTestCase.__init__(self, method_name) self._source = 'publish-test-source' self._project_file = f'src/{String.convert_to_snake_case(self._source)}/{self._source}.json' @@ -39,13 +40,6 @@ class PublishTestCase(unittest.TestCase): CLICommands.new('console', self._source, '--ab', '--s') os.chdir(os.path.join(os.getcwd(), self._source)) - def cleanUp(self): - # remove projects - if not os.path.exists(os.path.abspath(os.path.join(PLAYGROUND_PATH, self._source))): - return - - shutil.rmtree(os.path.abspath(os.path.join(PLAYGROUND_PATH, self._source))) - def _are_dir_trees_equal(self, dir1, dir2): """ found at https://stackoverflow.com/questions/4187564/recursively-compare-two-directories-to-ensure-they-have-the-same-files-and-subdi diff --git a/unittests/unittests_cli/remove_test_case.py b/unittests/unittests_cli/remove_test_case.py index f618e4b8..ac2732f3 100644 --- a/unittests/unittests_cli/remove_test_case.py +++ b/unittests/unittests_cli/remove_test_case.py @@ -3,14 +3,15 @@ import os import unittest from cpl_core.utils import String +from unittests_cli.abc.command_test_case import CommandTestCase from unittests_cli.constants import PLAYGROUND_PATH from unittests_shared.cli_commands import CLICommands -class RemoveTestCase(unittest.TestCase): +class RemoveTestCase(CommandTestCase): - def __init__(self, methodName: str): - unittest.TestCase.__init__(self, methodName) + def __init__(self, method_name: str): + CommandTestCase.__init__(self, method_name) self._source = 'add-test-project' self._target = 'add-test-library' self._project_file = f'src/{String.convert_to_snake_case(self._source)}/{self._source}.json' diff --git a/unittests/unittests_cli/run_test_case.py b/unittests/unittests_cli/run_test_case.py index 7ec9b9dd..23841a79 100644 --- a/unittests/unittests_cli/run_test_case.py +++ b/unittests/unittests_cli/run_test_case.py @@ -1,22 +1,18 @@ import json import os import shutil -import subprocess -import sys import unittest -import pkg_resources - from cpl_core.utils import String - +from unittests_cli.abc.command_test_case import CommandTestCase from unittests_cli.constants import PLAYGROUND_PATH from unittests_shared.cli_commands import CLICommands -class RunTestCase(unittest.TestCase): +class RunTestCase(CommandTestCase): - def __init__(self, methodName: str): - unittest.TestCase.__init__(self, methodName) + def __init__(self, method_name: str): + CommandTestCase.__init__(self, method_name) self._source = 'run-test' self._project_file = f'src/{String.convert_to_snake_case(self._source)}/{self._source}.json' self._appsettings = f'src/{String.convert_to_snake_case(self._source)}/appsettings.json' @@ -63,13 +59,6 @@ class RunTestCase(unittest.TestCase): file.write(f'\t\t{self._test_code}') file.close() - def cleanUp(self): - # remove projects - if not os.path.exists(os.path.abspath(os.path.join(PLAYGROUND_PATH, self._source))): - return - - shutil.rmtree(os.path.abspath(os.path.join(PLAYGROUND_PATH, self._source))) - def test_run(self): CLICommands.run() settings = self._get_appsettings() diff --git a/unittests/unittests_cli/start_test_case.py b/unittests/unittests_cli/start_test_case.py index 3ff09294..b0949f14 100644 --- a/unittests/unittests_cli/start_test_case.py +++ b/unittests/unittests_cli/start_test_case.py @@ -5,15 +5,16 @@ import time import unittest from cpl_core.utils import String +from unittests_cli.abc.command_test_case import CommandTestCase from unittests_cli.constants import PLAYGROUND_PATH from unittests_cli.threads.start_test_thread import StartTestThread from unittests_shared.cli_commands import CLICommands -class StartTestCase(unittest.TestCase): +class StartTestCase(CommandTestCase): - def __init__(self, methodName: str): - unittest.TestCase.__init__(self, methodName) + def __init__(self, method_name: str): + CommandTestCase.__init__(self, method_name) self._source = 'start-test' self._project_file = f'src/{String.convert_to_snake_case(self._source)}/{self._source}.json' self._appsettings = f'src/{String.convert_to_snake_case(self._source)}/appsettings.json' @@ -63,13 +64,6 @@ class StartTestCase(unittest.TestCase): file.write(f'\t\t{self._test_code}') file.close() - def cleanUp(self): - # remove projects - if not os.path.exists(os.path.abspath(os.path.join(PLAYGROUND_PATH, self._source))): - return - - shutil.rmtree(os.path.abspath(os.path.join(PLAYGROUND_PATH, self._source))) - def test_start(self): thread = StartTestThread() thread.start() diff --git a/unittests/unittests_cli/uninstall_test_case.py b/unittests/unittests_cli/uninstall_test_case.py index a552bfc2..b61dfafa 100644 --- a/unittests/unittests_cli/uninstall_test_case.py +++ b/unittests/unittests_cli/uninstall_test_case.py @@ -6,14 +6,15 @@ import sys import unittest from cpl_core.utils import String +from unittests_cli.abc.command_test_case import CommandTestCase from unittests_cli.constants import PLAYGROUND_PATH from unittests_shared.cli_commands import CLICommands -class UninstallTestCase(unittest.TestCase): +class UninstallTestCase(CommandTestCase): - def __init__(self, methodName: str): - unittest.TestCase.__init__(self, methodName) + def __init__(self, method_name: str): + CommandTestCase.__init__(self, method_name) self._source = 'uninstall-test-source' self._project_file = f'src/{String.convert_to_snake_case(self._source)}/{self._source}.json' self._version = '1.7.3' @@ -31,19 +32,12 @@ class UninstallTestCase(unittest.TestCase): def setUp(self): if not os.path.exists(PLAYGROUND_PATH): os.makedirs(PLAYGROUND_PATH) - + os.chdir(PLAYGROUND_PATH) # create projects CLICommands.new('console', self._source, '--ab', '--s') os.chdir(os.path.join(os.getcwd(), self._source)) - def cleanUp(self): - # remove projects - if not os.path.exists(os.path.abspath(os.path.join(PLAYGROUND_PATH, self._source))): - return - - shutil.rmtree(os.path.abspath(os.path.join(PLAYGROUND_PATH, self._source))) - def _get_installed_packages(self) -> dict: reqs = subprocess.check_output([sys.executable, '-m', 'pip', 'freeze']) return dict([tuple(r.decode().split('==')) for r in reqs.split()]) diff --git a/unittests/unittests_cli/update_test_case.py b/unittests/unittests_cli/update_test_case.py index 3b50b38c..b6e40243 100644 --- a/unittests/unittests_cli/update_test_case.py +++ b/unittests/unittests_cli/update_test_case.py @@ -6,14 +6,15 @@ import sys import unittest from cpl_core.utils import String +from unittests_cli.abc.command_test_case import CommandTestCase from unittests_cli.constants import PLAYGROUND_PATH from unittests_shared.cli_commands import CLICommands -class UpdateTestCase(unittest.TestCase): +class UpdateTestCase(CommandTestCase): - def __init__(self, methodName: str): - unittest.TestCase.__init__(self, methodName) + def __init__(self, method_name: str): + CommandTestCase.__init__(self, method_name) self._source = 'install-test-source' self._project_file = f'src/{String.convert_to_snake_case(self._source)}/{self._source}.json' @@ -26,6 +27,15 @@ class UpdateTestCase(unittest.TestCase): self._new_package_name = 'discord.py' self._new_package = f'{self._new_package_name}=={self._new_version}' + def setUp(self): + CLICommands.uninstall(self._old_package) + CLICommands.uninstall(self._new_package) + os.chdir(PLAYGROUND_PATH) + # create projects + CLICommands.new('console', self._source, '--ab', '--s') + os.chdir(os.path.join(os.getcwd(), self._source)) + CLICommands.install(self._old_package) + def _get_project_settings(self): with open(os.path.join(os.getcwd(), self._project_file), 'r', encoding='utf-8') as cfg: # load json @@ -39,22 +49,6 @@ class UpdateTestCase(unittest.TestCase): project_file.write(json.dumps(settings, indent=2)) project_file.close() - def setUp(self): - CLICommands.uninstall(self._old_package) - CLICommands.uninstall(self._new_package) - os.chdir(os.path.abspath(PLAYGROUND_PATH)) - # create projects - CLICommands.new('console', self._source, '--ab', '--s') - os.chdir(os.path.join(os.getcwd(), self._source)) - CLICommands.install(self._old_package) - - def cleanUp(self): - # remove projects - if not os.path.exists(os.path.abspath(os.path.join(PLAYGROUND_PATH, self._source))): - return - - shutil.rmtree(os.path.abspath(os.path.join(PLAYGROUND_PATH, self._source))) - def _get_installed_packages(self) -> dict: reqs = subprocess.check_output([sys.executable, '-m', 'pip', 'freeze']) return dict([tuple(r.decode().split('==')) for r in reqs.split()]) @@ -85,5 +79,3 @@ class UpdateTestCase(unittest.TestCase): packages = self._get_installed_packages() self.assertIn(self._new_package_name, packages) self.assertEqual(self._new_version, packages[self._new_package_name]) - - diff --git a/unittests/unittests_cli/version_test_case.py b/unittests/unittests_cli/version_test_case.py index 18e63b14..d409db77 100644 --- a/unittests/unittests_cli/version_test_case.py +++ b/unittests/unittests_cli/version_test_case.py @@ -12,13 +12,14 @@ import cpl_cli from cpl_core.console import ForegroundColorEnum from termcolor import colored +from unittests_cli.abc.command_test_case import CommandTestCase from unittests_shared.cli_commands import CLICommands -class VersionTestCase(unittest.TestCase): +class VersionTestCase(CommandTestCase): - def __init__(self, methodName: str): - unittest.TestCase.__init__(self, methodName) + def __init__(self, method_name: str): + CommandTestCase.__init__(self, method_name) self._block_banner = "" self._block_version = "" self._block_package_header = "" diff --git a/unittests/unittests_shared/cli_commands.py b/unittests/unittests_shared/cli_commands.py index 8ca6ccfc..ee7821f4 100644 --- a/unittests/unittests_shared/cli_commands.py +++ b/unittests/unittests_shared/cli_commands.py @@ -1,5 +1,6 @@ import os import subprocess +import sys from unittests_cli.constants import CLI_PATH @@ -29,7 +30,8 @@ class CLICommands: for arg in args: command.append(arg) - return subprocess.run(command, env=env_vars, check=True, capture_output=True, text=True).stdout + with subprocess.Popen(command, stdout=subprocess.PIPE, universal_newlines=True) as process: + return process.stdout.read() @classmethod def add(cls, source: str, target: str, output=False): diff --git a/unittests/unittests_translation/translation_test_suite.py b/unittests/unittests_translation/translation_test_suite.py index f1e15132..f0d5a3da 100644 --- a/unittests/unittests_translation/translation_test_suite.py +++ b/unittests/unittests_translation/translation_test_suite.py @@ -1,11 +1,7 @@ -import os -import shutil -import traceback import unittest from typing import Optional from unittest import TestResult -from unittests_cli.constants import PLAYGROUND_PATH from unittests_translation.translation_test_case import TranslationTestCase @@ -25,27 +21,5 @@ class TranslationTestSuite(unittest.TestSuite): for test in active_tests: self.addTests(loader.loadTestsFromTestCase(test)) - def _setup(self): - try: - if os.path.exists(PLAYGROUND_PATH): - shutil.rmtree(os.path.abspath(os.path.join(PLAYGROUND_PATH))) - - os.makedirs(PLAYGROUND_PATH) - os.chdir(PLAYGROUND_PATH) - except Exception as e: - print(f'Setup of {__name__} failed: {traceback.format_exc()}') - - def _cleanup(self): - try: - if self._result is not None and (len(self._result.errors) > 0 or len(self._result.failures) > 0): - return - - if os.path.exists(PLAYGROUND_PATH): - shutil.rmtree(os.path.abspath(os.path.join(PLAYGROUND_PATH))) - except Exception as e: - print(f'Cleanup of {__name__} failed: {traceback.format_exc()}') - def run(self, *args): - self._setup() self._result = super().run(*args) - self._cleanup()