diff --git a/ci_scripts/test.sh b/ci_scripts/test.sh index 80b35f04f0..2a837583e4 100644 --- a/ci_scripts/test.sh +++ b/ci_scripts/test.sh @@ -22,7 +22,7 @@ run_tests() { PYTEST_ARGS='' fi - pytest -n 4 --duration=20 --timeout=600 --timeout-method=thread -sv --ignore='test_OpenMLDemo.py' $PYTEST_ARGS $test_dir + pytest -n 4 --durations=20 --timeout=600 --timeout-method=thread -sv --ignore='test_OpenMLDemo.py' $PYTEST_ARGS $test_dir } if [[ "$RUN_FLAKE8" == "true" ]]; then diff --git a/doc/progress.rst b/doc/progress.rst index d001dbb30c..739c17f799 100644 --- a/doc/progress.rst +++ b/doc/progress.rst @@ -8,11 +8,14 @@ Changelog 0.10.0 ~~~~~~ +* FIX #261: Test server is cleared of all files uploaded during unit testing. +* FIX #447: All files created by unit tests no longer persist in local. * FIX #589: Fixing a bug that did not successfully upload the columns to ignore when creating and publishing a dataset. * DOC #639: More descriptive documention for function to convert array format. * ADD #687: Adds a function to retrieve the list of evaluation measures available. * ADD #695: A function to retrieve all the data quality measures available. + 0.9.0 ~~~~~ * ADD #560: OpenML-Python can now handle regression tasks as well. diff --git a/openml/testing.py b/openml/testing.py index 1ce0862d03..bfead021f5 100644 --- a/openml/testing.py +++ b/openml/testing.py @@ -17,6 +17,8 @@ import openml from openml.tasks import TaskTypeEnum +import pytest + class TestBase(unittest.TestCase): """Base class for tests @@ -26,6 +28,9 @@ class TestBase(unittest.TestCase): Currently hard-codes a read-write key. Hopefully soon allows using a test server, not the production server. """ + tracker = {} + test_server = None + apikey = None def setUp(self, n_levels: int = 1): """Setup variables and temporary directories. @@ -75,6 +80,10 @@ def setUp(self, n_levels: int = 1): self.production_server = "https://openml.org/api/v1/xml" self.test_server = "https://test.openml.org/api/v1/xml" + # For global file deletion on test server + TestBase.test_server = self.test_server + TestBase.apikey = openml.config.apikey + openml.config.server = self.test_server openml.config.avoid_duplicate_runs = False openml.config.cache_directory = self.workdir @@ -103,6 +112,66 @@ def tearDown(self): openml.config.server = self.production_server openml.config.connection_n_retries = self.connection_n_retries + @classmethod + def _track_test_server_dumps(self, entity_type, entity_id): + if entity_type not in TestBase.tracker: + TestBase.tracker[entity_type] = [entity_id] + else: + TestBase.tracker[entity_type].append(entity_id) + + @pytest.fixture(scope="session", autouse=True) + def _cleanup_fixture(self): + """Cleans up files generated by Unit tests + + This function is called at the beginning of the invocation of + TestBase (defined below), by each of class that inherits TestBase. + The 'yield' creates a checkpoint and breaks away to continue running + the unit tests of the sub class. When all the tests end, execution + resumes from the checkpoint. + """ + # TODO: generalize this path better akin to static_cache_dir + directory = "{}/tests/files/".format(os.getcwd()) + files = os.walk(directory) + old_file_list = [] + for root, _, filenames in files: + for filename in filenames: + old_file_list.append(os.path.join(root, filename)) + # context switches to other remaining tests + # pauses the code execution here till all tests in the 'session' is over + yield + # resumes from here after all collected tests are completed + files = os.walk(directory) + new_file_list = [] + for root, _, filenames in files: + for filename in filenames: + new_file_list.append(os.path.join(root, filename)) + # filtering the files generated during this run + new_file_list = list(set(new_file_list) - set(old_file_list)) + print("Deleting local files generated...") + for file in new_file_list: + os.remove(file) + + # Test server deletion + print("Deleting files uploaded to test server...") + openml.config.server = TestBase.test_server + openml.config.apikey = TestBase.apikey + + entity_types = list(TestBase.tracker.keys()) + # deleting 'run' first to allow other dependent entities to be deleted + if 'run' in entity_types: + index = entity_types.index('run') + # putting 'run' in the start of the list + entity_types[0], entity_types[index] = entity_types[index], entity_types[0] + + for entity_type in entity_types: + for i, entity in enumerate(TestBase.tracker[entity_type]): + try: + openml.utils._delete_entity(entity_type, entity) + print("Deleted ({}, {})".format(entity_type, entity)) + TestBase.tracker[entity_type].pop(i) + except Exception as e: + print("Cannot delete ({}, {}): {}".format(entity_type, entity, e)) + def _get_sentinel(self, sentinel=None): if sentinel is None: # Create a unique prefix for the flow. Necessary because the flow diff --git a/tests/test_datasets/test_dataset_functions.py b/tests/test_datasets/test_dataset_functions.py index 21d7676c5f..1d99fc3eea 100644 --- a/tests/test_datasets/test_dataset_functions.py +++ b/tests/test_datasets/test_dataset_functions.py @@ -1,4 +1,5 @@ import os +import sys import random from itertools import product from unittest import mock @@ -43,14 +44,18 @@ def tearDown(self): super(TestOpenMLDataset, self).tearDown() def _remove_pickle_files(self): - cache_dir = self.static_cache_dir + self.lock_path = os.path.join(openml.config.get_cache_directory(), 'locks') for did in ['-1', '2']: with lockutils.external_lock( name='datasets.functions.get_dataset:%s' % did, - lock_path=os.path.join(openml.config.get_cache_directory(), 'locks'), + lock_path=self.lock_path, ): - pickle_path = os.path.join(cache_dir, 'datasets', did, - 'dataset.pkl') + if sys.version[0] == '3': + pickle_path = os.path.join(openml.config.get_cache_directory(), 'datasets', + did, 'dataset.pkl.py3') + else: + pickle_path = os.path.join(openml.config.get_cache_directory(), 'datasets', + did, 'dataset.pkl') try: os.remove(pickle_path) except (OSError, FileNotFoundError): @@ -478,6 +483,8 @@ def test_publish_dataset(self): data_file=file_path, ) dataset.publish() + TestBase._track_test_server_dumps('data', dataset.dataset_id) + print("\ncollected from {}: {}".format( __file__.split('/')[-1], dataset.dataset_id)) self.assertIsInstance(dataset.dataset_id, int) def test__retrieve_class_labels(self): @@ -498,6 +505,8 @@ def test_upload_dataset_with_url(self): url="https://www.openml.org/data/download/61/dataset_61_iris.arff", ) dataset.publish() + TestBase._track_test_server_dumps('data', dataset.dataset_id) + print("\ncollected from {}: {}".format( __file__.split('/')[-1], dataset.dataset_id)) self.assertIsInstance(dataset.dataset_id, int) def test_data_status(self): @@ -507,6 +516,8 @@ def test_data_status(self): version=1, url="https://www.openml.org/data/download/61/dataset_61_iris.arff") dataset.publish() + TestBase._track_test_server_dumps('data', dataset.dataset_id) + print("\ncollected from {}: {}".format( __file__.split('/')[-1], dataset.dataset_id)) did = dataset.dataset_id # admin key for test server (only adminds can activate datasets. @@ -620,6 +631,8 @@ def test_create_dataset_numpy(self): ) upload_did = dataset.publish() + TestBase._track_test_server_dumps('data', upload_did) + print("\ncollected from {}: {}".format( __file__.split('/')[-1], upload_did)) self.assertEqual( _get_online_dataset_arff(upload_did), @@ -682,6 +695,8 @@ def test_create_dataset_list(self): ) upload_did = dataset.publish() + TestBase._track_test_server_dumps('data', upload_did) + print("\ncollected from {}: {}".format( __file__.split('/')[-1], upload_did)) self.assertEqual( _get_online_dataset_arff(upload_did), dataset._dataset, @@ -725,6 +740,8 @@ def test_create_dataset_sparse(self): ) upload_did = xor_dataset.publish() + TestBase._track_test_server_dumps('data', upload_did) + print("\ncollected from {}: {}".format( __file__.split('/')[-1], upload_did)) self.assertEqual( _get_online_dataset_arff(upload_did), xor_dataset._dataset, @@ -762,6 +779,8 @@ def test_create_dataset_sparse(self): ) upload_did = xor_dataset.publish() + TestBase._track_test_server_dumps('data', upload_did) + print("\ncollected from {}: {}".format( __file__.split('/')[-1], upload_did)) self.assertEqual( _get_online_dataset_arff(upload_did), xor_dataset._dataset, @@ -885,6 +904,8 @@ def test_create_dataset_pandas(self): paper_url=paper_url ) upload_did = dataset.publish() + TestBase._track_test_server_dumps('data', upload_did) + print("\ncollected from {}: {}".format( __file__.split('/')[-1], upload_did)) self.assertEqual( _get_online_dataset_arff(upload_did), dataset._dataset, @@ -919,6 +940,8 @@ def test_create_dataset_pandas(self): paper_url=paper_url ) upload_did = dataset.publish() + TestBase._track_test_server_dumps('data', upload_did) + print("\ncollected from {}: {}".format( __file__.split('/')[-1], upload_did)) self.assertEqual( _get_online_dataset_arff(upload_did), dataset._dataset, @@ -955,6 +978,8 @@ def test_create_dataset_pandas(self): paper_url=paper_url ) upload_did = dataset.publish() + TestBase._track_test_server_dumps('data', upload_did) + print("\ncollected from {}: {}".format( __file__.split('/')[-1], upload_did)) downloaded_data = _get_online_dataset_arff(upload_did) self.assertEqual( downloaded_data, @@ -1123,6 +1148,8 @@ def test___publish_fetch_ignore_attribute(self): # publish dataset upload_did = dataset.publish() + TestBase._track_test_server_dumps('data', upload_did) + print("\ncollected from {}: {}".format( __file__.split('/')[-1], upload_did)) # test if publish was successful self.assertIsInstance(upload_did, int) # variables to carry forward for test_publish_fetch_ignore_attribute() @@ -1253,6 +1280,8 @@ def test_create_dataset_row_id_attribute_inference(self): ) self.assertEqual(dataset.row_id_attribute, output_row_id) upload_did = dataset.publish() + TestBase._track_test_server_dumps('data', upload_did) + print("\ncollected from {}: {}".format( __file__.split('/')[-1], upload_did)) arff_dataset = arff.loads(_get_online_dataset_arff(upload_did)) arff_data = np.array(arff_dataset['data'], dtype=object) # if we set the name of the index then the index will be added to diff --git a/tests/test_extensions/test_sklearn_extension/test_sklearn_extension.py b/tests/test_extensions/test_sklearn_extension/test_sklearn_extension.py index aef064ad51..85940f9bfe 100644 --- a/tests/test_extensions/test_sklearn_extension/test_sklearn_extension.py +++ b/tests/test_extensions/test_sklearn_extension/test_sklearn_extension.py @@ -1126,6 +1126,8 @@ def test_openml_param_name_to_sklearn(self): task = openml.tasks.get_task(115) run = openml.runs.run_flow_on_task(flow, task) run = run.publish() + TestBase._track_test_server_dumps('run', run.run_id) + print("\ncollected from {}: {}".format( __file__.split('/')[-1], run.run_id)) run = openml.runs.get_run(run.run_id) setup = openml.setups.get_setup(run.setup_id) diff --git a/tests/test_flows/test_flow.py b/tests/test_flows/test_flow.py index 7b8c66cab2..65bbe1227f 100644 --- a/tests/test_flows/test_flow.py +++ b/tests/test_flows/test_flow.py @@ -41,6 +41,10 @@ def setUp(self): super().setUp() self.extension = openml.extensions.sklearn.SklearnExtension() + def tearDown(self): + # TestBase.tracker.append(TestFlow.tracker) + super().tearDown() + def test_get_flow(self): # We need to use the production server here because 4024 is not the # test server @@ -177,6 +181,8 @@ def test_publish_flow(self): flow, _ = self._add_sentinel_to_flow_name(flow, None) flow.publish() + self._track_test_server_dumps('flow', flow.flow_id) + print("\ncollected from {}: {}".format( __file__.split('/')[-1], flow.flow_id)) self.assertIsInstance(flow.flow_id, int) @mock.patch('openml.flows.functions.flow_exists') @@ -187,6 +193,9 @@ def test_publish_existing_flow(self, flow_exists_mock): with self.assertRaises(openml.exceptions.PyOpenMLError) as context_manager: flow.publish(raise_error_if_exists=True) + self._track_test_server_dumps('flow', flow.flow_id) + print("\ncollected from {}: {}".format( __file__.split('/')[-1], flow.flow_id)) + print(TestFlow.tracker) self.assertTrue('OpenMLFlow already exists' in context_manager.exception.message) @@ -197,6 +206,8 @@ def test_publish_flow_with_similar_components(self): flow = self.extension.model_to_flow(clf) flow, _ = self._add_sentinel_to_flow_name(flow, None) flow.publish() + self._track_test_server_dumps('flow', flow.flow_id) + print("\ncollected from {}: {}".format( __file__.split('/')[-1], flow.flow_id)) # For a flow where both components are published together, the upload # date should be equal self.assertEqual( @@ -213,6 +224,9 @@ def test_publish_flow_with_similar_components(self): flow1 = self.extension.model_to_flow(clf1) flow1, sentinel = self._add_sentinel_to_flow_name(flow1, None) flow1.publish() + self._track_test_server_dumps('flow', flow1.flow_id) + print("\ncollected from {}: {}".format( __file__.split('/')[-1], flow1.flow_id)) + print(TestFlow.tracker) # In order to assign different upload times to the flows! time.sleep(1) @@ -222,6 +236,8 @@ def test_publish_flow_with_similar_components(self): flow2 = self.extension.model_to_flow(clf2) flow2, _ = self._add_sentinel_to_flow_name(flow2, sentinel) flow2.publish() + self._track_test_server_dumps('flow', flow2.flow_id) + print("\ncollected from {}: {}".format( __file__.split('/')[-1], flow2.flow_id)) # If one component was published before the other, the components in # the flow should have different upload dates self.assertNotEqual(flow2.upload_date, @@ -234,6 +250,8 @@ def test_publish_flow_with_similar_components(self): # Child flow has different parameter. Check for storing the flow # correctly on the server should thus not check the child's parameters! flow3.publish() + self._track_test_server_dumps('flow', flow3.flow_id) + print("\ncollected from {}: {}".format( __file__.split('/')[-1], flow3.flow_id)) def test_semi_legal_flow(self): # TODO: Test if parameters are set correctly! @@ -246,6 +264,8 @@ def test_semi_legal_flow(self): flow, _ = self._add_sentinel_to_flow_name(flow, None) flow.publish() + self._track_test_server_dumps('flow', flow.flow_id) + print("\ncollected from {}: {}".format( __file__.split('/')[-1], flow.flow_id)) @mock.patch('openml.flows.functions.get_flow') @mock.patch('openml.flows.functions.flow_exists') @@ -260,6 +280,8 @@ def test_publish_error(self, api_call_mock, flow_exists_mock, get_flow_mock): get_flow_mock.return_value = flow flow.publish() + self._track_test_server_dumps('flow', flow.flow_id) + print("\ncollected from {}: {}".format( __file__.split('/')[-1], flow.flow_id)) self.assertEqual(api_call_mock.call_count, 1) self.assertEqual(get_flow_mock.call_count, 1) self.assertEqual(flow_exists_mock.call_count, 1) @@ -271,6 +293,8 @@ def test_publish_error(self, api_call_mock, flow_exists_mock, get_flow_mock): with self.assertRaises(ValueError) as context_manager: flow.publish() + self._track_test_server_dumps('flow', flow.flow_id) + print("\ncollected from {}: {}".format( __file__.split('/')[-1], flow.flow_id)) fixture = ( "Flow was not stored correctly on the server. " @@ -336,6 +360,8 @@ def test_existing_flow_exists(self): flow, _ = self._add_sentinel_to_flow_name(flow, None) # publish the flow flow = flow.publish() + self._track_test_server_dumps('flow', flow.flow_id) + print("\ncollected from {}: {}".format( __file__.split('/')[-1], flow.flow_id)) # redownload the flow flow = openml.flows.get_flow(flow.flow_id) @@ -394,6 +420,8 @@ def test_sklearn_to_upload_to_flow(self): flow, sentinel = self._add_sentinel_to_flow_name(flow, None) flow.publish() + self._track_test_server_dumps('flow', flow.flow_id) + print("\ncollected from {}: {}".format( __file__.split('/')[-1], flow.flow_id)) self.assertIsInstance(flow.flow_id, int) # Check whether we can load the flow again diff --git a/tests/test_flows/test_flow_functions.py b/tests/test_flows/test_flow_functions.py index 087623d3d3..f4e581a46f 100644 --- a/tests/test_flows/test_flow_functions.py +++ b/tests/test_flows/test_flow_functions.py @@ -251,6 +251,8 @@ def test_sklearn_to_flow_list_of_lists(self): # Test flow is accepted by server self._add_sentinel_to_flow_name(flow) flow.publish() + TestBase._track_test_server_dumps('flow', flow.flow_id) + print("\ncollected from {}: {}".format( __file__.split('/')[-1], flow.flow_id)) # Test deserialization works server_flow = openml.flows.get_flow(flow.flow_id, reinstantiate=True) diff --git a/tests/test_runs/test_run.py b/tests/test_runs/test_run.py index bba14b3241..3503803ad4 100644 --- a/tests/test_runs/test_run.py +++ b/tests/test_runs/test_run.py @@ -129,6 +129,8 @@ def test_to_from_filesystem_vanilla(self): self.assertTrue(run_prime.flow is None) self._test_run_obj_equals(run, run_prime) run_prime.publish() + TestBase._track_test_server_dumps('run', run_prime.run_id) + print("\ncollected from {}: {}".format(__file__.split('/')[-1], run_prime.run_id)) def test_to_from_filesystem_search(self): @@ -162,6 +164,8 @@ def test_to_from_filesystem_search(self): run_prime = openml.runs.OpenMLRun.from_filesystem(cache_path) self._test_run_obj_equals(run, run_prime) run_prime.publish() + TestBase._track_test_server_dumps('run', run_prime.run_id) + print("\ncollected from {}: {}".format(__file__.split('/')[-1], run_prime.run_id)) def test_to_from_filesystem_no_model(self): @@ -226,6 +230,8 @@ def test_publish_with_local_loaded_flow(self): # obtain run from filesystem loaded_run = openml.runs.OpenMLRun.from_filesystem(cache_path) loaded_run.publish() + TestBase._track_test_server_dumps('run', loaded_run.run_id) + print("\ncollected from {}: {}".format( __file__.split('/')[-1], loaded_run.run_id)) # make sure the flow is published as part of publishing the run. self.assertTrue(openml.flows.flow_exists(flow.name, flow.external_version)) diff --git a/tests/test_runs/test_run_functions.py b/tests/test_runs/test_run_functions.py index 6c93043f88..e4fc227e49 100644 --- a/tests/test_runs/test_run_functions.py +++ b/tests/test_runs/test_run_functions.py @@ -184,6 +184,8 @@ def _remove_random_state(flow): flow, _ = self._add_sentinel_to_flow_name(flow, sentinel) if not openml.flows.flow_exists(flow.name, flow.external_version): flow.publish() + TestBase._track_test_server_dumps('flow', flow.flow_id) + print("\ncollected from test_run_functions: {}".format(flow.flow_id)) task = openml.tasks.get_task(task_id) @@ -196,6 +198,8 @@ def _remove_random_state(flow): avoid_duplicate_runs=openml.config.avoid_duplicate_runs, ) run_ = run.publish() + TestBase._track_test_server_dumps('run', run.run_id) + print("\ncollected from test_run_functions: {}".format(run.run_id)) self.assertEqual(run_, run) self.assertIsInstance(run.dataset_id, int) @@ -687,6 +691,8 @@ def test_initialize_cv_from_run(self): seed=1, ) run_ = run.publish() + TestBase._track_test_server_dumps('run', run.run_id) + print("\ncollected from test_run_functions: {}".format(run.run_id)) run = openml.runs.get_run(run_.run_id) modelR = openml.runs.initialize_model_from_run(run_id=run.run_id) @@ -802,6 +808,8 @@ def test_initialize_model_from_run(self): avoid_duplicate_runs=False, ) run_ = run.publish() + TestBase._track_test_server_dumps('run', run_.run_id) + print("\ncollected from test_run_functions: {}".format(run_.run_id)) run = openml.runs.get_run(run_.run_id) modelR = openml.runs.initialize_model_from_run(run_id=run.run_id) @@ -853,6 +861,8 @@ def test_get_run_trace(self): num_iterations * num_folds, ) run = run.publish() + TestBase._track_test_server_dumps('run', run.run_id) + print("\ncollected from test_run_functions: {}".format(run.run_id)) self._wait_for_processed_run(run.run_id, 200) run_id = run.run_id except openml.exceptions.OpenMLRunsExistError as e: @@ -897,6 +907,8 @@ def test__run_exists(self): upload_flow=True ) run.publish() + TestBase._track_test_server_dumps('run', run.run_id) + print("\ncollected from test_run_functions: {}".format(run.run_id)) except openml.exceptions.PyOpenMLError: # run already existed. Great. pass @@ -957,6 +969,8 @@ def test_run_with_illegal_flow_id_after_load(self): "but 'flow.flow_id' is not None.") with self.assertRaisesRegex(openml.exceptions.PyOpenMLError, expected_message_regex): loaded_run.publish() + TestBase._track_test_server_dumps('run', loaded_run.run_id) + print("\ncollected from test_run_functions: {}".format(loaded_run.run_id)) def test_run_with_illegal_flow_id_1(self): # Check the case where the user adds an illegal flow id to an existing @@ -966,6 +980,8 @@ def test_run_with_illegal_flow_id_1(self): flow_orig = self.extension.model_to_flow(clf) try: flow_orig.publish() # ensures flow exist on server + TestBase._track_test_server_dumps('flow', flow_orig.flow_id) + print("\ncollected from test_run_functions: {}".format(flow_orig.flow_id)) except openml.exceptions.OpenMLServerException: # flow already exists pass @@ -991,6 +1007,8 @@ def test_run_with_illegal_flow_id_1_after_load(self): flow_orig = self.extension.model_to_flow(clf) try: flow_orig.publish() # ensures flow exist on server + TestBase._track_test_server_dumps('flow', flow_orig.flow_id) + print("\ncollected from test_run_functions: {}".format(flow_orig.flow_id)) except openml.exceptions.OpenMLServerException: # flow already exists pass @@ -1263,6 +1281,8 @@ def test_run_model_on_task_downloaded_flow(self): model = sklearn.ensemble.RandomForestClassifier(n_estimators=33) flow = self.extension.model_to_flow(model) flow.publish(raise_error_if_exists=False) + TestBase._track_test_server_dumps('flow', flow.flow_id) + print("\ncollected from test_run_functions: {}".format(flow.flow_id)) downloaded_flow = openml.flows.get_flow(flow.flow_id, reinstantiate=True) task = openml.tasks.get_task(119) # diabetes @@ -1274,3 +1294,5 @@ def test_run_model_on_task_downloaded_flow(self): ) run.publish() + TestBase._track_test_server_dumps('run', run.run_id) + print("\ncollected from {}: {}".format(__file__.split('/')[-1], run.run_id)) diff --git a/tests/test_setups/test_setup_functions.py b/tests/test_setups/test_setup_functions.py index a8f7de4d4d..8ce3da532d 100644 --- a/tests/test_setups/test_setup_functions.py +++ b/tests/test_setups/test_setup_functions.py @@ -40,6 +40,8 @@ def test_nonexisting_setup_exists(self): flow = self.extension.model_to_flow(dectree) flow.name = 'TEST%s%s' % (sentinel, flow.name) flow.publish() + self._track_test_server_dumps('flow', flow.flow_id) + print("\ncollected from {}: {}".format( __file__.split('/')[-1], flow.flow_id)) # although the flow exists (created as of previous statement), # we can be sure there are no setups (yet) as it was just created @@ -52,6 +54,8 @@ def _existing_setup_exists(self, classif): flow = self.extension.model_to_flow(classif) flow.name = 'TEST%s%s' % (get_sentinel(), flow.name) flow.publish() + self._track_test_server_dumps('flow', flow.flow_id) + print("\ncollected from {}: {}".format( __file__.split('/')[-1], flow.flow_id)) # although the flow exists, we can be sure there are no # setups (yet) as it hasn't been ran @@ -66,6 +70,8 @@ def _existing_setup_exists(self, classif): # spoof flow id, otherwise the sentinel is ignored run.flow_id = flow.flow_id run.publish() + self._track_test_server_dumps('run', run.run_id) + print("\ncollected from {}: {}".format( __file__.split('/')[-1], run.run_id)) # download the run, as it contains the right setup id run = openml.runs.get_run(run.run_id) diff --git a/tests/test_study/test_study_examples.py b/tests/test_study/test_study_examples.py index abee2d72aa..477327ca81 100644 --- a/tests/test_study/test_study_examples.py +++ b/tests/test_study/test_study_examples.py @@ -51,4 +51,6 @@ def test_Figure1a(self): ) # print accuracy score print('Data set: %s; Accuracy: %0.2f' % (task.get_dataset().name, score.mean())) run.publish() # publish the experiment on OpenML (optional) + self._track_test_server_dumps('run', run.run_id) + print("\ncollected from {}: {}".format( __file__.split('/')[-1], run.run_id)) print('URL for run: %s/run/%d' % (openml.config.server, run.run_id)) diff --git a/tests/test_study/test_study_functions.py b/tests/test_study/test_study_functions.py index c87dd8e159..c23b9776eb 100644 --- a/tests/test_study/test_study_functions.py +++ b/tests/test_study/test_study_functions.py @@ -77,6 +77,9 @@ def test_publish_benchmark_suite(self): task_ids=fixture_task_ids ) study_id = study.publish() + self._track_test_server_dumps('study', study_id) + print("\ncollected from {}: {}".format( __file__.split('/')[-1], study_id)) + self.assertGreater(study_id, 0) # verify main meta data @@ -132,6 +135,8 @@ def test_publish_study(self): run_ids=list(run_list.keys()) ) study_id = study.publish() + self._track_test_server_dumps('study', study_id) + print("\ncollected from {}: {}".format( __file__.split('/')[-1], study_id)) self.assertGreater(study_id, 0) study_downloaded = openml.study.get_study(study_id) self.assertEqual(study_downloaded.alias, fixt_alias) @@ -181,6 +186,8 @@ def test_study_attach_illegal(self): run_ids=list(run_list.keys()) ) study_id = study.publish() + self._track_test_server_dumps('study', study_id) + print("\ncollected from {}: {}".format( __file__.split('/')[-1], study_id)) study_original = openml.study.get_study(study_id) with self.assertRaisesRegex(openml.exceptions.OpenMLServerException, diff --git a/tests/test_tasks/test_clustering_task.py b/tests/test_tasks/test_clustering_task.py index 21e03052fe..645a5d3e9a 100644 --- a/tests/test_tasks/test_clustering_task.py +++ b/tests/test_tasks/test_clustering_task.py @@ -43,4 +43,6 @@ def test_upload_task(self): ) task_id = task.publish() + TestBase._track_test_server_dumps('task', task_id) + print("\ncollected from {}: {}".format( __file__.split('/')[-1], task_id)) openml.utils._delete_entity('task', task_id) diff --git a/tests/test_tasks/test_split.py b/tests/test_tasks/test_split.py index 46c6564a13..bbb2a26000 100644 --- a/tests/test_tasks/test_split.py +++ b/tests/test_tasks/test_split.py @@ -1,4 +1,5 @@ import inspect +import sys import os import numpy as np @@ -20,7 +21,10 @@ def setUp(self): "tasks", "1882", "datasplits.arff" ) # TODO Needs to be adapted regarding the python version - self.pd_filename = self.arff_filename.replace(".arff", ".pkl") + if sys.version[0] == '3': + self.pd_filename = self.arff_filename.replace(".arff", ".pkl.py3") + else: + self.pd_filename = self.arff_filename.replace(".arff", ".pkl") def tearDown(self): try: diff --git a/tests/test_tasks/test_task.py b/tests/test_tasks/test_task.py index fe7fa5f0ef..d97f9cf091 100644 --- a/tests/test_tasks/test_task.py +++ b/tests/test_tasks/test_task.py @@ -59,6 +59,8 @@ def test_upload_task(self): ) task_id = task.publish() + TestBase._track_test_server_dumps('task', task_id) + print("\ncollected from {}: {}".format( __file__.split('/')[-1], task_id)) # success break except OpenMLServerException as e: diff --git a/tests/test_tasks/test_task_functions.py b/tests/test_tasks/test_task_functions.py index dfdbd4847a..f773752d55 100644 --- a/tests/test_tasks/test_task_functions.py +++ b/tests/test_tasks/test_task_functions.py @@ -12,6 +12,12 @@ class TestTask(TestBase): _multiprocess_can_split_ = True + def setUp(self): + super(TestTask, self).setUp() + + def tearDown(self): + super(TestTask, self).tearDown() + def test__get_cached_tasks(self): openml.config.cache_directory = self.static_cache_dir tasks = openml.tasks.functions._get_cached_tasks() diff --git a/tests/test_tasks/test_task_methods.py b/tests/test_tasks/test_task_methods.py index 55cbba64b2..4a07894148 100644 --- a/tests/test_tasks/test_task_methods.py +++ b/tests/test_tasks/test_task_methods.py @@ -7,6 +7,12 @@ # Common methods between tasks class OpenMLTaskMethodsTest(TestBase): + def setUp(self): + super(OpenMLTaskMethodsTest, self).setUp() + + def tearDown(self): + super(OpenMLTaskMethodsTest, self).tearDown() + def test_tagging(self): task = openml.tasks.get_task(1) tag = "testing_tag_{}_{}".format(self.id(), time())