|
2 | 2 | import time |
3 | 3 | import xmltodict |
4 | 4 | import pytest |
5 | | -from openml.testing import TestAPIBase |
| 5 | +from openml.testing import TestBase, TestAPIBase |
6 | 6 | import os |
7 | 7 | from pathlib import Path |
8 | 8 | from urllib.parse import urljoin |
@@ -155,27 +155,22 @@ def test_post_and_delete(self): |
155 | 155 | <oml:input name="estimation_procedure">17</oml:input> |
156 | 156 | </oml:task_inputs> |
157 | 157 | """ |
| 158 | + # post |
| 159 | + response = self.http_client.post( |
| 160 | + "task", |
| 161 | + files={"description": task_xml}, |
| 162 | + ) |
| 163 | + self.assertEqual(response.status_code, 200) |
| 164 | + xml_resp = xmltodict.parse(response.content) |
| 165 | + task_id = int(xml_resp["oml:upload_task"]["oml:id"]) |
158 | 166 |
|
159 | | - task_id = None |
160 | | - try: |
161 | | - # POST the task |
162 | | - post_response = self.http_client.post( |
163 | | - "task", |
164 | | - files={"description": task_xml}, |
165 | | - ) |
166 | | - self.assertEqual(post_response.status_code, 200) |
167 | | - xml_resp = xmltodict.parse(post_response.content) |
168 | | - task_id = int(xml_resp["oml:upload_task"]["oml:id"]) |
169 | | - |
170 | | - # GET the task to verify it exists |
171 | | - get_response = self.http_client.get(f"task/{task_id}") |
172 | | - self.assertEqual(get_response.status_code, 200) |
173 | | - |
174 | | - finally: |
175 | | - # DELETE the task if it was created |
176 | | - if task_id is not None: |
177 | | - del_response = self.http_client.delete(f"task/{task_id}") |
178 | | - self.assertEqual(del_response.status_code, 200) |
| 167 | + # cleanup incase of failure |
| 168 | + TestBase._mark_entity_for_removal("task", task_id) |
| 169 | + TestBase.logger.info(f"collected from {__file__}: {task_id}") |
| 170 | + |
| 171 | + # delete |
| 172 | + response = self.http_client.delete(f"task/{task_id}") |
| 173 | + self.assertEqual(response.status_code, 200) |
179 | 174 |
|
180 | 175 | def test_download_requires_cache(self): |
181 | 176 | client = HTTPClient( |
|
0 commit comments