Skip to content

Commit 78ca6d8

Browse files
author
Martin Vrachev
committed
Tests decorator: save case name
Save the case name in the "unittest.TestCase" object when executing test cases through the "run_sub_tests_with_dataset" decorator. This allows dumping directories with names specific to the test case that can be used for debugging as showed in test_updater_key_rotations.py Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
1 parent f3a8aa0 commit 78ca6d8

2 files changed

Lines changed: 3 additions & 4 deletions

File tree

tests/test_updater_key_rotations.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ class TestUpdaterKeyRotations(unittest.TestCase):
4040
def setUpClass(cls) -> None:
4141
cls.sim: RepositorySimulator
4242
cls.metadata_dir: str
43-
cls.subtest_count = 0
4443
# pylint: disable-next=consider-using-with
4544
cls.temp_dir = tempfile.TemporaryDirectory()
4645

@@ -57,16 +56,14 @@ def tearDownClass(cls) -> None:
5756
cls.temp_dir.cleanup()
5857

5958
def setup_subtest(self) -> None:
60-
self.subtest_count += 1
61-
6259
# Setup repository for subtest: make sure no roots have been published
6360
self.sim = RepositorySimulator()
6461
self.sim.signed_roots.clear()
6562
self.sim.root.version = 0
6663

6764
if self.dump_dir is not None:
6865
# create subtest dumpdir
69-
name = f"{self.id().split('.')[-1]}-{self.subtest_count}"
66+
name = f"{self.id().split('.')[-1]}-{self.case_name}"
7067
self.sim.dump_dir = os.path.join(self.dump_dir, name)
7168
os.mkdir(self.sim.dump_dir)
7269

tests/utils.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ def real_decorator(
5757
def wrapper(test_cls: unittest.TestCase) -> None:
5858
for case, data in dataset.items():
5959
with test_cls.subTest(case=case):
60+
# Save case name for future reference
61+
test_cls.case_name = case.replace(" ", "_")
6062
function(test_cls, data)
6163
return wrapper
6264
return real_decorator

0 commit comments

Comments
 (0)