diff options
author | xianyuanjia <56282287+xianyuanjia@users.noreply.github.com> | 2021-08-23 01:20:40 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-22 22:20:40 -0700 |
commit | b4c874145c152e995471e81b1452216c635dc5d2 (patch) | |
tree | 57f7530a64fdff37c9835209a4e6c34d427688b5 | |
parent | 5de78a96c9da39b8ece187e28c4edb724a2a7c45 (diff) | |
download | mobly-b4c874145c152e995471e81b1452216c635dc5d2.tar.gz |
Inspect class instead of class instance to get test methods list. (#762)
-rw-r--r-- | mobly/base_test.py | 2 | ||||
-rwxr-xr-x | tests/mobly/base_test_test.py | 15 |
2 files changed, 16 insertions, 1 deletions
diff --git a/mobly/base_test.py b/mobly/base_test.py index d6e9faa..97caece 100644 --- a/mobly/base_test.py +++ b/mobly/base_test.py @@ -905,7 +905,7 @@ class BaseTestClass: A list of strings, each is a test method name. """ test_names = [] - for name, _ in inspect.getmembers(self, callable): + for name, _ in inspect.getmembers(type(self), callable): if name.startswith('test_'): test_names.append(name) return test_names + list(self._generated_test_table.keys()) diff --git a/tests/mobly/base_test_test.py b/tests/mobly/base_test_test.py index e9a7e80..f8a9a87 100755 --- a/tests/mobly/base_test_test.py +++ b/tests/mobly/base_test_test.py @@ -274,6 +274,21 @@ class BaseTestTest(unittest.TestCase): mock_decorated.assert_called_once_with('test_decorated') mock_undecorated.assert_called_once_with('test_undecorated') + def test_get_existing_tests_do_not_call_properties(self): + + class MockBaseTest(base_test.BaseTestClass): + + def test_something(self): + pass + + @property + def not_a_test(self): + # This property should not be called during get_existing_tests() + never_call() + + bt_cls = MockBaseTest(self.mock_test_cls_configs) + bt_cls.run() + def test_missing_requested_test_func(self): class MockBaseTest(base_test.BaseTestClass): |