Skip to content

Commit

Permalink
fix: restore test_suite_1
Browse files Browse the repository at this point in the history
  • Loading branch information
Pog3k committed Feb 3, 2025
1 parent 23e4fa5 commit f6e8e0e
Showing 1 changed file with 85 additions and 43 deletions.
128 changes: 85 additions & 43 deletions examples/test_suite_1/test_suite_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,10 @@

import importlib
import logging
import time
from itertools import cycle

import pykiso
import pykiso.profiling
from pykiso.auxiliaries import aux1, aux2, aux3
from pykiso.profiling import get_tracer, profile_manager

# define an external iterator that can be used for retry_test_case demo
side_effect = cycle([False, False, True])
Expand Down Expand Up @@ -83,6 +80,7 @@ class MyTest1(pykiso.BasicTest):
-> tag: [optional] allows the run of subset of tests
"""

@pykiso.retry_test_case(max_try=3)
def setUp(self):
"""Hook method from unittest in order to execute code before test case run.
In this case the default setUp method is overridden, allowing us to apply the
Expand All @@ -91,8 +89,8 @@ def setUp(self):
"""
super().setUp()

@pykiso.profiling.profile(compress=False)
def test_run1(self):
@pykiso.retry_test_case(max_try=5, rerun_setup=True, rerun_teardown=True)
def test_run(self):
"""In this case the default test_run method is overridden and
instead of calling test_run from RemoteTest class the following
code is called.
Expand All @@ -103,47 +101,10 @@ def test_run1(self):
logging.info(f"--------------- RUN: {self.test_suite_id}, {self.test_case_id} ---------------")
# define any additional key-value pair that will appear as property in the JUnit report
self.properties = {"testrail_attachment": "some/path/to/afile.txt"}
time.sleep(1)
logging.info(f"I HAVE RUN 0.1.1 for tag {self.tag}!")
self.assertTrue(True)

def test_run2(self):
"""In this case the default test_run method is overridden and
instead of calling test_run from RemoteTest class the following
code is called.
Here, the test pass at the 3rd attempt out of 5. The setup and
tearDown methods are called for each attempt.
"""
logging.info("TAG daily")
logging.info(f"--------------- RUN: {self.test_suite_id}, {self.test_case_id} ---------------")
# define any additional key-value pair that will appear as property in the JUnit report
with profile_manager("testrun2.json", compress=False):
time.sleep(1)
logging.info(f"I HAVE RUN 0.1.1 for tag {self.tag}!")
time.sleep(1)
self.assertTrue(True)
self.assertTrue(next(side_effect))
logging.info(f"I HAVE RUN 0.1.1 for tag {self.tag}!")

def test_run3(self):
"""In this case the default test_run method is overridden and
instead of calling test_run from RemoteTest class the following
code is called.
Here, the test pass at the 3rd attempt out of 5. The setup and
tearDown methods are called for each attempt.
"""
logging.info("TAG daily")
logging.info(f"--------------- RUN: {self.test_suite_id}, {self.test_case_id} ---------------")
# define any additional key-value pair that will appear as property in the JUnit report
time.sleep(1)
local_tracer = get_tracer()
local_tracer.start()
logging.info(f"I HAVE RUN 0.1.1 for tag {self.tag}!")
time.sleep(1)
local_tracer.stop()
local_tracer.save("testrun3.json")
logging.info(f"I HAVE RUN 0.1.1 for tag {self.tag}!")
self.assertTrue(True)

@pykiso.retry_test_case(max_try=3)
def tearDown(self):
"""Hook method from unittest in order to execute code after the test case ran.
Expand All @@ -152,3 +113,84 @@ def tearDown(self):
we will run the default tearDown()
"""
super().tearDown()


@pykiso.define_test_parameters(
suite_id=1,
case_id=2,
aux_list=[aux2, aux3],
setup_timeout=1,
run_timeout=2,
teardown_timeout=1,
test_ids={"Component1": ["Req"]},
tag={"branch_level": ["nightly"]},
)
class MyTest2(pykiso.RemoteTest):
"""This test case definition will be executed using base behavior
given by RemoteTest.
Using decorator define_test_parameters the following parameters will
be applied on test case setUp, test_run and tearDown:
-> suite_id : set to 1
-> case_id : set to 2
-> aux_list : test case test_run, setUp, and tearDown executed using
aux2, aux3 (see yaml configuration file)
-> setup_timeout : ITF will wait 1 seconds (maximum) to receive a
report from device under test otherwise an abort command is sent.
-> run_timeout : ITF will wait 2 seconds (maximum) to receive a
report from device under test otherwise an abort command is sent.
-> teardown_timeout : ITF will wait 1 seconds (maximum) to receive a
report from device under test otherwise an abort command is sent.
-> test_ids: [optional] store the requirements into the report
-> tag: [optional] allows the run of subset of tests
If setup_timeout, run_timeout and teardown_timeout are not given the
default timeout value is 10 seconds for each.
"""

@pykiso.retry_test_case(max_try=3, rerun_setup=False, rerun_teardown=False, stability_test=True)
def test_run(self):
"""In this case the default test_run method is called using the
python syntax super(), in addition aux3, aux2 running is paused
and resumed.
This test will be run 3 times in order to test stability (setUp
and tearDown excluded as the flags are set to False).
"""
logging.info(f"------------suspend auxiliaries run-------------")
logging.info("TAG nightly")
aux3.suspend()
aux2.suspend()
logging.info(f"------------resume auxiliaries run--------------")
aux3.resume()
aux2.resume()
super().test_run()
logging.info("I HAVE RUN 0.1.2!")


@pykiso.define_test_parameters(
suite_id=1,
case_id=3,
aux_list=[aux1, aux3],
setup_timeout=5,
run_timeout=2,
teardown_timeout=3,
tag={"variant": ["variant3"]},
)
class MyTest3(pykiso.RemoteTest):
"""This test case definition will be executed using base behavior
given by RemoteTest.
Using decorator define_test_parameters the following parameters will
be applied on test case setUp, test_run and tearDown:
-> suite_id : set to 1
-> case_id : set to 3
-> aux_list : test case test_run, setUp, and tearDown executed using
aux1(see yaml configuration file)
-> setup_timeout : ITF will wait 5 seconds (maximum) to receive a
report from device under test otherwise an abort command is sent.
-> run_timeout : ITF will wait 2 seconds (maximum) to receive a
report from device under test otherwise an abort command is sent.
-> teardown_timeout : ITF will wait 3 seconds (maximum) to receive a
report from device under test otherwise an abort command is sent.
-> test_ids: [optional] store the requirements into the report
-> tag: [optional] allows the run of subset of tests
If setup_timeout, run_timeout and teardown_timeout are not given the
default timeout value is 10 seconds for each.
"""

0 comments on commit f6e8e0e

Please sign in to comment.