| 61 | |
| 62 | == Using several test methods |
| 63 | |
| 64 | You can use several test methods within a `TestCase` class; they need to start with `test`. When you use method `setUp` it will be executed for each test method. If you only want to "set up" your test environment once of your test case, you need to use class method `setUpClass`. |
| 65 | |
| 66 | For example: |
| 67 | {{{#!py |
| 68 | # ... imports and such ... |
| 69 | class TestApi(unittest.TestCase): |
| 70 | |
| 71 | @classmethod |
| 72 | def setUpClass(self, port=None): |
| 73 | super(TestApi, self).setUpClass() |
| 74 | self.env = EnvironmentStub(enable=[ |
| 75 | 'trac.*', 'logwatcher.api' |
| 76 | ]) |
| 77 | # ... more lines ... |
| 78 | |
| 79 | def test_get_logfile_name(self): |
| 80 | # ... more lines ... |
| 81 | |
| 82 | def test_get_log_settings_default(self): |
| 83 | # ... more lines ... |
| 84 | |
| 85 | @classmethod |
| 86 | def tearDownClass(self): |
| 87 | super(TestApi, self).tearDownClass() |
| 88 | # you should also shutdown environment before deleting directory, |
| 89 | # since it closes log files, shutdowns database connection and such |
| 90 | self.env.shutdown() |
| 91 | shutil.rmtree(dirPath) |
| 92 | }}} |