зеркало из https://github.com/microsoft/lisa.git
use before_case and after_case replace before_suite and after_suite
This commit is contained in:
Родитель
8b08f7ac0f
Коммит
97b9490765
|
@ -67,13 +67,6 @@ class HelloWorld(TestSuite):
|
|||
node.tools.get(Echo) # Ensure echo is in cache
|
||||
assert_that(str(node.tools.echo("bye!"))).is_equal_to("bye!")
|
||||
|
||||
def before_suite(self, log: Logger, **kwargs: Any) -> None:
|
||||
log.info("setup my test suite")
|
||||
log.info(f"see my code at {__file__}")
|
||||
|
||||
def after_suite(self, log: Logger, **kwargs: Any) -> None:
|
||||
log.info("clean up my test suite")
|
||||
|
||||
def before_case(self, log: Logger, **kwargs: Any) -> None:
|
||||
log.info("before test case")
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ from lisa import (
|
|||
""",
|
||||
)
|
||||
class WithScript(TestSuite):
|
||||
def before_suite(self, log: Logger, **kwargs: Any) -> None:
|
||||
def before_case(self, log: Logger, **kwargs: Any) -> None:
|
||||
self._echo_script = CustomScriptBuilder(
|
||||
Path(__file__).parent.joinpath("scripts"), ["echo.sh"]
|
||||
)
|
||||
|
|
|
@ -30,22 +30,19 @@ from microsoft.testsuites.cloud_hypervisor.ch_tests_tool import CloudHypervisorT
|
|||
""",
|
||||
)
|
||||
class CloudHypervisorTestSuite(TestSuite):
|
||||
def before_suite(self, log: Logger, **kwargs: Any) -> None:
|
||||
node = kwargs["node"]
|
||||
node.tools[Modprobe].load("openvswitch")
|
||||
|
||||
def after_suite(self, log: Logger, **kwargs: Any) -> None:
|
||||
node = kwargs["node"]
|
||||
node.tools[Modprobe].remove(["openvswitch"])
|
||||
|
||||
def before_case(self, log: Logger, **kwargs: Any) -> None:
|
||||
node = kwargs["node"]
|
||||
if not isinstance(node.os, (CBLMariner, Ubuntu)):
|
||||
raise SkippedException(
|
||||
f"Cloud Hypervisor tests are not implemented in LISA for {node.os.name}"
|
||||
)
|
||||
node.tools[Modprobe].load("openvswitch")
|
||||
self._ensure_virtualization_enabled(node)
|
||||
|
||||
def after_case(self, log: Logger, **kwargs: Any) -> None:
|
||||
node = kwargs["node"]
|
||||
node.tools[Modprobe].remove(["openvswitch"])
|
||||
|
||||
@TestCaseMetadata(
|
||||
description="""
|
||||
Runs cloud-hypervisor integration tests.
|
||||
|
|
|
@ -39,7 +39,7 @@ class MshvHostTestSuite(TestSuite):
|
|||
HYPERVISOR_FW_NAME = "hypervisor-fw"
|
||||
DISK_IMG_NAME = "vm_disk_img.raw"
|
||||
|
||||
def before_suite(self, log: Logger, **kwargs: Any) -> None:
|
||||
def before_case(self, log: Logger, **kwargs: Any) -> None:
|
||||
node = kwargs["node"]
|
||||
if not node.tools[Ls].path_exists("/dev/mshv", sudo=True):
|
||||
raise SkippedException("This suite is for MSHV root partition only")
|
||||
|
|
|
@ -416,9 +416,9 @@ class RunnerTestCase(TestCase):
|
|||
test_results=test_results,
|
||||
)
|
||||
|
||||
def test_skipped_on_suite_failure(self) -> None:
|
||||
def test_skipped_on_case_failure(self) -> None:
|
||||
# First two tests were skipped because the setup is made to fail.
|
||||
test_testsuite.fail_on_before_suite = True
|
||||
test_testsuite.fail_on_before_case = True
|
||||
test_testsuite.generate_cases_metadata()
|
||||
env_runbook = generate_env_runbook(is_single_env=True, local=True, remote=True)
|
||||
runner = generate_runner(env_runbook)
|
||||
|
@ -431,7 +431,7 @@ class RunnerTestCase(TestCase):
|
|||
runner=runner,
|
||||
)
|
||||
|
||||
before_suite_failed = "before_suite: failed"
|
||||
before_case_failed = "before_case: failed"
|
||||
self.verify_test_results(
|
||||
expected_test_order=["mock_ut1", "mock_ut2", "mock_ut3"],
|
||||
expected_envs=["customized_0", "customized_0", "customized_0"],
|
||||
|
@ -440,7 +440,7 @@ class RunnerTestCase(TestCase):
|
|||
TestStatus.SKIPPED,
|
||||
TestStatus.PASSED,
|
||||
],
|
||||
expected_message=[before_suite_failed, before_suite_failed, ""],
|
||||
expected_message=[before_case_failed, before_case_failed, ""],
|
||||
test_results=test_results,
|
||||
)
|
||||
|
||||
|
|
|
@ -28,8 +28,6 @@ from lisa.util.logger import Logger
|
|||
from selftests.test_environment import generate_runbook
|
||||
|
||||
# for other UTs
|
||||
fail_on_before_suite = False
|
||||
fail_on_after_suite = False
|
||||
fail_on_before_case = False
|
||||
fail_on_after_case = False
|
||||
partial_pass = False
|
||||
|
@ -42,8 +40,6 @@ check_variable = False
|
|||
class MockTestSuite(TestSuite):
|
||||
def __init__(self, *args: Any, **kwargs: Any) -> None:
|
||||
super().__init__(*args, **kwargs)
|
||||
self.fail_on_before_suite = fail_on_before_suite
|
||||
self.fail_on_after_suite = fail_on_after_suite
|
||||
self.fail_on_before_case = fail_on_before_case
|
||||
self.fail_on_after_case = fail_on_after_case
|
||||
self.partial_pass = partial_pass
|
||||
|
@ -55,8 +51,6 @@ class MockTestSuite(TestSuite):
|
|||
|
||||
def set_fail_phase(
|
||||
self,
|
||||
fail_on_before_suite: bool = False,
|
||||
fail_on_after_suite: bool = False,
|
||||
fail_on_before_case: bool = False,
|
||||
fail_on_after_case: bool = False,
|
||||
partial_pass: bool = False,
|
||||
|
@ -64,8 +58,6 @@ class MockTestSuite(TestSuite):
|
|||
fail_case_count: int = 0,
|
||||
check_variable: bool = False,
|
||||
) -> None:
|
||||
self.fail_on_before_suite = fail_on_before_suite
|
||||
self.fail_on_after_suite = fail_on_after_suite
|
||||
self.fail_on_before_case = fail_on_before_case
|
||||
self.fail_on_after_case = fail_on_after_case
|
||||
self.partial_pass = partial_pass
|
||||
|
@ -73,14 +65,6 @@ class MockTestSuite(TestSuite):
|
|||
self.fail_case_count = fail_case_count
|
||||
self.check_variable = check_variable
|
||||
|
||||
def before_suite(self, log: Logger, **kwargs: Any) -> None:
|
||||
if self.fail_on_before_suite:
|
||||
raise LisaException("failed")
|
||||
|
||||
def after_suite(self, log: Logger, **kwargs: Any) -> None:
|
||||
if self.fail_on_after_suite:
|
||||
raise LisaException("failed")
|
||||
|
||||
def before_case(self, log: Logger, **kwargs: Any) -> None:
|
||||
if self.fail_on_before_case:
|
||||
raise LisaException("failed")
|
||||
|
@ -226,30 +210,6 @@ class TestSuiteTestCase(TestCase):
|
|||
else:
|
||||
self.assertEqual(False, result.is_queued)
|
||||
|
||||
def test_skip_before_suite_failed(self) -> None:
|
||||
test_suite = self.generate_suite_instance()
|
||||
test_suite.set_fail_phase(fail_on_before_suite=True)
|
||||
test_suite.start(
|
||||
environment=self.default_env,
|
||||
case_results=self.case_results,
|
||||
case_variables={},
|
||||
)
|
||||
for result in self.case_results:
|
||||
self.assertEqual(TestStatus.SKIPPED, result.status)
|
||||
self.assertEqual("before_suite: failed", result.message)
|
||||
|
||||
def test_pass_after_suite_failed(self) -> None:
|
||||
test_suite = self.generate_suite_instance()
|
||||
test_suite.set_fail_phase(fail_on_after_suite=True)
|
||||
test_suite.start(
|
||||
environment=self.default_env,
|
||||
case_results=self.case_results,
|
||||
case_variables={},
|
||||
)
|
||||
for result in self.case_results:
|
||||
self.assertEqual(TestStatus.PASSED, result.status)
|
||||
self.assertEqual("", result.message)
|
||||
|
||||
def test_variable_exists(self) -> None:
|
||||
test_suite = self.generate_suite_instance()
|
||||
test_suite.set_fail_phase(check_variable=True)
|
||||
|
|
Загрузка…
Ссылка в новой задаче