From b9f71c72720ac7c921c3db1013b3c0f2f4e0763f Mon Sep 17 00:00:00 2001 From: Jesse Vickery Date: Mon, 9 Dec 2024 19:52:21 +0000 Subject: [PATCH] fix(tests): simplify; - Simplify test with specific file suffix check. --- ckanext/xloader/tests/test_jobs.py | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/ckanext/xloader/tests/test_jobs.py b/ckanext/xloader/tests/test_jobs.py index 74ed5a6e..269eb95c 100644 --- a/ckanext/xloader/tests/test_jobs.py +++ b/ckanext/xloader/tests/test_jobs.py @@ -90,14 +90,6 @@ def data(create_with_upload, apikey): @pytest.mark.ckan_config("ckan.jobs.timeout", 15) class TestXLoaderJobs(helpers.FunctionalRQTestBase): - @classmethod - def setup_method(self, method): - """Method is called at class level before EACH test methods of the class are called. - Setup any state specific to the execution of the given class methods. - """ - for f in _get_temp_files(): - os.remove(f) - def test_xloader_data_into_datastore(self, cli, data): self.enqueue(jobs.xloader_data_into_datastore, [data]) with mock.patch("ckanext.xloader.jobs.get_response", get_response): @@ -146,13 +138,14 @@ def test_data_max_excerpt_lines_config(self, cli, data): assert resource["datastore_contains_all_records_of_source_file"] is False def test_data_with_rq_job_timeout(self, cli, data): - assert len(_get_temp_files()) == 0 + file_suffix = 'multiplication_2.csv' self.enqueue(jobs.xloader_data_into_datastore, [data], rq_kwargs=dict(timeout=15)) with mock.patch("ckanext.xloader.jobs.get_response", get_large_data_response): stdout = cli.invoke(ckan, ["jobs", "worker", "--burst"]).output assert "Job timed out after" in stdout - assert len(_get_temp_files()) == 0 - + for f in _get_temp_files(): + # make sure that the tmp file has been closed/deleted in job timeout exception handling + assert file_suffix not in f @pytest.mark.usefixtures("clean_db")