Pythonのunittest.TestLoaderのメソッド loadTestsFromNames
unittest.TestLoader クラスには loadTestsFromNames というメソッドが存在します。このメソッドは、複数のテスト名(テストメソッドまたはテストクラスの名前)を指定して、それに対応するテストスイートを作成し、そのテストスイート内のテストケースを収集します。
以下は、loadTestsFromNames メソッドを使用して複数のテスト名からテストスイートを作成する例です:
python
import unittest class MyTestCase(unittest.TestCase): def test_example(self): self.assertEqual(1, 1) class AnotherTestCase(unittest.TestCase): def test_another_example(self): self.assertTrue(True) if __name__ == '__main__': # 複数のテスト名からテストスイートを作成 test_loader = unittest.TestLoader() test_suite = test_loader.loadTestsFromNames(["MyTestCase.test_example", "AnotherTestCase.test_another_example"]) # テストスイートを実行 test_runner = unittest.TextTestRunner() test_runner.run(test_suite)
上記の例では、unittest.TestLoader クラスの loadTestsFromNames メソッドを使用して、複数のテスト名から対応するテストスイートを作成し、そのテストスイートを実行しています。
loadTestsFromNames メソッドは、複数のテストケースやテストメソッドの名前を指定し、それらを一つのテストスイートにまとめるのに便利です。これにより、複数のテストを一度に実行できます。また、テストの選択的な実行やカスタムテストランナーの使用時にも役立ちます。

ディスカッション
コメント一覧
まだ、コメントがありません