Skip to content

Commit

Permalink
Add some docs
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiitk committed Jan 19, 2024
1 parent c00c601 commit 60c4a14
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 14 deletions.
27 changes: 15 additions & 12 deletions framework/test_cases/base_testcase.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,21 @@ def run(self, result: Optional[unittest.TestResult] = None) -> None:

@property
def test_name(self) -> str:
# Test id returned from self.id() can have two forms:
# 1. Regular: __main__.MyClassTest.test_method
# 2. Parametrized: __main__.MyClassTest.test_method{case} ('param'),
# where {case} is
# a) An integer for @parameterized.parameters: test_method0,
# test_method1, ...
# b) {testcase_name} for @parameterized.named_parameters:
# test_method_pass, test_method_fail, ...
#
# This method:
# 1. Removes "__main__." if it's present
# 2. Removes the " ('param')" if present
"""Pretty test name (details in the description).
Test id returned from self.id() can have two forms:
1. Regular: __main__.MyClassTest.test_method
2. Parametrized: __main__.MyClassTest.test_method{case} ('param'),
where {case} is
a) An integer for @parameterized.parameters: test_method0,
test_method1, ...
b) {testcase_name} for @parameterized.named_parameters:
test_method_pass, test_method_fail, ...
This method:
1. Removes "__main__." if it's present
2. Removes the " ('param')" if present
"""
return self.id().removeprefix("__main__.").split(" ", 1)[0]

def _print_error_list(
Expand Down
13 changes: 11 additions & 2 deletions tests/fake_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@


class FakeTest(xds_k8s_testcase.XdsKubernetesBaseTestCase):
"""A fake test with known failures to debug BaseTestCase logs.
"""A fake test class with known failures to debug BaseTestCase logs.
This test case won't do any infra provisioning, just parses the flags and
reads k8s contexts file.
Expand All @@ -50,6 +50,11 @@ class FakeParametrizedTest(
xds_k8s_testcase.XdsKubernetesBaseTestCase,
parameterized.TestCase,
):
"""A fake class to debug BaseTestCase logs produced by parametrized tests.
See FakeTest for notes on provisioning.
"""

@parameterized.parameters(True, False)
def test_true(self, is_true):
self.assertTrue(is_true)
Expand All @@ -63,7 +68,11 @@ def test_true_named(self, is_true):


class FakeSubtestTest(xds_k8s_testcase.XdsKubernetesBaseTestCase):
# TODO(sergiitk): add subtest examples
"""A fake class to debug BaseTestCase logs produced by tests with subtests.
See FakeTest for notes on provisioning.
"""

def test_even(self):
for num in range(0, 6):
with self.subTest(i=num, msg=f"num_{num}"):
Expand Down

0 comments on commit 60c4a14

Please sign in to comment.