From 9a95603c01fbe272aa94e7ae5a1aa4081f175842 Mon Sep 17 00:00:00 2001 From: Sascha Klawohn <sascha.klawohn@physik.hu-berlin.de> Date: Thu, 21 Dec 2023 11:07:35 +0100 Subject: [PATCH] Remove redundant fixture mongo --- tests/app/test_optimade.py | 2 +- tests/app/test_resources.py | 2 +- tests/app/v1/routers/test_datasets.py | 2 +- tests/app/v1/routers/test_entries_edit.py | 6 ++--- tests/app/v1/routers/test_uploads.py | 6 ++--- tests/archive/test_archive.py | 8 +++---- tests/conftest.py | 16 ++++--------- tests/data/test_examples.py | 10 ++++++-- .../datamodel/metainfo/eln/test_labfolder.py | 4 ++-- tests/datamodel/metainfo/eln/test_openbis.py | 2 +- .../metainfo/eln/test_perovskite_database.py | 2 +- tests/datamodel/metainfo/eln/test_system.py | 4 ++-- tests/examples/test_archive_query.py | 2 +- tests/metainfo/test_mongodb_extension.py | 4 ++-- tests/parsing/test_tabular.py | 2 +- .../test_perovskite_database.py | 2 +- tests/processing/test_base.py | 24 ++++++++++--------- tests/processing/test_data.py | 4 ++-- tests/test_cli.py | 2 +- tests/test_doi.py | 8 +++---- 20 files changed, 57 insertions(+), 55 deletions(-) diff --git a/tests/app/test_optimade.py b/tests/app/test_optimade.py index 77933d55c2..0cbe4a4e51 100644 --- a/tests/app/test_optimade.py +++ b/tests/app/test_optimade.py @@ -39,7 +39,7 @@ def test_get_entry(published: Upload): assert 'optimade.chemical_formula_hill' in utils.flatten_dict(search_result) -def test_no_optimade(mongo, elastic, raw_files_function, client, test_user): +def test_no_optimade(mongo_function, elastic, raw_files_function, client, test_user): example_data = ExampleData(main_author=test_user) example_data.create_upload( upload_id='test_upload', published=True, embargo_length=0 diff --git a/tests/app/test_resources.py b/tests/app/test_resources.py index 9bf3b0814f..17172f73fa 100644 --- a/tests/app/test_resources.py +++ b/tests/app/test_resources.py @@ -92,7 +92,7 @@ def patched_download(monkeypatch): @pytest.fixture(scope='function') -def resources(mongo, monkeypatch): +def resources(mongo_function, monkeypatch): monkeypatch.setattr('nomad.config.resources.enabled', True) monkeypatch.setattr('nomad.config.resources.db_name', 'test_db_resources') remove_mongo() diff --git a/tests/app/v1/routers/test_datasets.py b/tests/app/v1/routers/test_datasets.py index 9ae58c8401..edf7715307 100644 --- a/tests/app/v1/routers/test_datasets.py +++ b/tests/app/v1/routers/test_datasets.py @@ -54,7 +54,7 @@ def create_dataset(**kwargs): @pytest.fixture(scope='function') -def data(elastic, raw_files_function, mongo, test_user, other_test_user): +def data(elastic, raw_files_function, mongo_function, test_user, other_test_user): data = ExampleData(main_author=test_user) data.create_upload(upload_id='upload_1', published=True) data.create_entry( diff --git a/tests/app/v1/routers/test_entries_edit.py b/tests/app/v1/routers/test_entries_edit.py index 19785d725d..56cd1d6353 100644 --- a/tests/app/v1/routers/test_entries_edit.py +++ b/tests/app/v1/routers/test_entries_edit.py @@ -40,11 +40,11 @@ class TestEditRepo: return {'upload_id:any': uploads} @pytest.fixture(autouse=True) - def set_api(self, client, elastic, mongo): + def set_api(self, client, elastic, mongo_function): self.api = client @pytest.fixture(autouse=True) - def example_datasets(self, test_user, other_test_user, mongo): + def example_datasets(self, test_user, other_test_user, mongo_function): self.example_dataset = Dataset( dataset_id='example_ds', dataset_name='example_ds', @@ -61,7 +61,7 @@ class TestEditRepo: @pytest.fixture(autouse=True) def example_data( - self, test_user, other_test_user, raw_files_function, elastic, mongo + self, test_user, other_test_user, raw_files_function, elastic, mongo_function ): # TODO example_data = ExampleData() diff --git a/tests/app/v1/routers/test_uploads.py b/tests/app/v1/routers/test_uploads.py index e95a593658..e8cfd1d6f5 100644 --- a/tests/app/v1/routers/test_uploads.py +++ b/tests/app/v1/routers/test_uploads.py @@ -3135,7 +3135,7 @@ def test_post_upload_edit( ) def test_post_upload( client, - mongo, + mongo_function, proc_infra, monkeypatch, test_auth_dict, @@ -3394,7 +3394,7 @@ def test_post_upload_action_publish_to_central_nomad( ) def test_post_upload_action_process( client, - mongo, + mongo_function, proc_infra, monkeypatch, example_data_writeable, @@ -3503,7 +3503,7 @@ def test_post_upload_action_process( ) def test_post_upload_action_delete_entry_files( client, - mongo, + mongo_function, proc_infra, example_data_writeable, test_auth_dict, diff --git a/tests/archive/test_archive.py b/tests/archive/test_archive.py index 3865d51ba2..e55b4cca7e 100644 --- a/tests/archive/test_archive.py +++ b/tests/archive/test_archive.py @@ -813,7 +813,7 @@ def all_archive(): ], ) def test_required_reader( - archive, required, inplace_result, root_result, resolve_inplace, mongo + archive, required, inplace_result, root_result, resolve_inplace, mongo_function ): f = BytesIO() write_archive(f, 1, [('entry_id', archive.m_to_dict())], entry_toc_depth=2) @@ -1243,12 +1243,12 @@ def test_partial_archive(archive): assert_partial_archive(partial_archive) -def test_partial_archive_read_write(archive, mongo): +def test_partial_archive_read_write(archive, mongo_function): write_partial_archive_to_mongo(archive) assert_partial_archive(read_partial_archive_from_mongo('test_id')) -def test_partial_archive_re_write(archive, mongo): +def test_partial_archive_re_write(archive, mongo_function): write_partial_archive_to_mongo(archive) archive.metadata.comment = 'changed' write_partial_archive_to_mongo(archive) @@ -1256,7 +1256,7 @@ def test_partial_archive_re_write(archive, mongo): assert archive.metadata.comment == 'changed' -def test_read_partial_archives(archive, mongo): +def test_read_partial_archives(archive, mongo_function): write_partial_archive_to_mongo(archive) assert_partial_archive(read_partial_archives_from_mongo(['test_id'])['test_id']) diff --git a/tests/conftest.py b/tests/conftest.py index be68effeaf..c531032542 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -193,7 +193,7 @@ def celery_inspect(purged_app): # It might be necessary to make this a function scoped fixture, if old tasks keep # 'bleeding' into successive tests. @pytest.fixture(scope='function') -def worker(mongo, celery_session_worker, celery_inspect): +def worker(mongo_function, celery_session_worker, celery_inspect): """Provides a clean worker (no old tasks) per function. Waits for all tasks to be completed.""" yield @@ -242,12 +242,6 @@ def mongo_function(mongo_infra): return clear_mongo(mongo_infra) -@pytest.fixture(scope='function') -def mongo(mongo_infra): - """Provides a cleaned mocked mongo per function.""" - return clear_mongo(mongo_infra) - - @pytest.fixture(scope='session') def elastic_infra(monkeysession): """Provides elastic infrastructure to the session""" @@ -444,7 +438,7 @@ def keycloak(monkeypatch): @pytest.fixture(scope='function') -def proc_infra(worker, elastic, mongo, raw_files_function): +def proc_infra(worker, elastic, mongo_function, raw_files_function): """Combines all fixtures necessary for processing (elastic, worker, files, mongo)""" return dict(elastic=elastic) @@ -1208,7 +1202,7 @@ def plugin_schema(): @pytest.fixture(scope='function') -def example_data_writeable(mongo, test_user, normalized): +def example_data_writeable(mongo_function, test_user, normalized): data = ExampleData(main_author=test_user) # one upload with one entry, published @@ -1246,7 +1240,7 @@ def example_data_writeable(mongo, test_user, normalized): @pytest.fixture(scope='function') -def example_datasets(mongo, test_user, other_test_user): +def example_datasets(mongo_function, test_user, other_test_user): dataset_specs = ( ('test_dataset_1', test_user, None), ('test_dataset_2', test_user, 'test_doi_2'), @@ -1283,7 +1277,7 @@ def reset_config(): @pytest.fixture -def reset_infra(mongo, elastic): +def reset_infra(mongo_function, elastic): """Fixture that resets infrastructure after deleting db or search index.""" yield None diff --git a/tests/data/test_examples.py b/tests/data/test_examples.py index 3d1068e8a7..2255a563ca 100644 --- a/tests/data/test_examples.py +++ b/tests/data/test_examples.py @@ -86,7 +86,7 @@ def test_sample_tabular(mainfile, assert_xpaths, raw_files_function, no_warn): ], ) def test_sample_entry_mode( - mongo, + mongo_function, test_user, raw_files_function, monkeypatch, @@ -212,7 +212,13 @@ def test_sample_entry_mode( ], ) def test_tabular_doc_examples( - mongo, test_user, raw_files_function, monkeypatch, proc_infra, test_files, status + mongo_function, + test_user, + raw_files_function, + monkeypatch, + proc_infra, + test_files, + status, ): upload = create_upload('test_upload_id', test_user.user_id, test_files) assert upload is not None diff --git a/tests/datamodel/metainfo/eln/test_labfolder.py b/tests/datamodel/metainfo/eln/test_labfolder.py index 6fe9297901..22b4be109d 100644 --- a/tests/datamodel/metainfo/eln/test_labfolder.py +++ b/tests/datamodel/metainfo/eln/test_labfolder.py @@ -33,7 +33,7 @@ from nomad.utils.exampledata import ExampleData from tests.test_files import example_mainfile_contents, append_raw_files # pylint: disable=unused-import -def test_labfolder_integration(mongo, monkeypatch, test_user): +def test_labfolder_integration(mongo_function, monkeypatch, test_user): directory = 'tests/data/datamodel/metainfo/eln/material_library' mainfile = 'example-labfolder.archive.json' @@ -187,7 +187,7 @@ def test_labfolder_integration(mongo, monkeypatch, test_user): ], ) def test_labfolder_detailed( - mongo, + mongo_function, monkeypatch, test_user, status_code, diff --git a/tests/datamodel/metainfo/eln/test_openbis.py b/tests/datamodel/metainfo/eln/test_openbis.py index f2c270d03e..1da5bfdde3 100644 --- a/tests/datamodel/metainfo/eln/test_openbis.py +++ b/tests/datamodel/metainfo/eln/test_openbis.py @@ -92,7 +92,7 @@ def mocked_login(url): ], ) def test_openbis( - mongo, + mongo_function, monkeypatch, test_user, status_code, diff --git a/tests/datamodel/metainfo/eln/test_perovskite_database.py b/tests/datamodel/metainfo/eln/test_perovskite_database.py index b1193c2b06..7391c86e50 100644 --- a/tests/datamodel/metainfo/eln/test_perovskite_database.py +++ b/tests/datamodel/metainfo/eln/test_perovskite_database.py @@ -22,7 +22,7 @@ from nomad.datamodel.context import ClientContext from nomad.utils.exampledata import ExampleData -def test_processing(raw_files_function, no_warn, test_user, mongo): +def test_processing(raw_files_function, no_warn, test_user, mongo_function): directory = 'tests/data/datamodel/metainfo/eln/perovskite_database' mainfile = 'example.archive.json' upload_id = 'test_upload_id' diff --git a/tests/datamodel/metainfo/eln/test_system.py b/tests/datamodel/metainfo/eln/test_system.py index 0817398506..ff025eff8e 100644 --- a/tests/datamodel/metainfo/eln/test_system.py +++ b/tests/datamodel/metainfo/eln/test_system.py @@ -28,7 +28,7 @@ from tests.normalizing.conftest import run_processing, run_normalize from nomad.datamodel.data import User -def test_substance(raw_files_function, test_user, mongo): +def test_substance(raw_files_function, test_user, mongo_function): directory = 'tests/data/datamodel/metainfo/eln' mainfile = 'test_substance.archive.yaml' upload_id = 'test_upload_id' @@ -53,7 +53,7 @@ def test_substance(raw_files_function, test_user, mongo): assert 'Pb' in test_archive.results.material.elements -def test_ensemble(raw_files_function, test_user, mongo): +def test_ensemble(raw_files_function, test_user, mongo_function): directory = 'tests/data/datamodel/metainfo/eln' mainfile = 'test_ensemble.archive.yaml' upload_id = 'test_upload_id' diff --git a/tests/examples/test_archive_query.py b/tests/examples/test_archive_query.py index 5170f49cbf..3a9a028746 100644 --- a/tests/examples/test_archive_query.py +++ b/tests/examples/test_archive_query.py @@ -28,7 +28,7 @@ from tests.test_client import async_api_v1 def test_archive_query( - async_api_v1, elastic, raw_files_function, mongo, test_user, capsys + async_api_v1, elastic, raw_files_function, mongo_function, test_user, capsys ): mainfile = os.path.join( __file__, '..', '..', 'data', 'examples', 'archive_query_vasprun.xml.gz' diff --git a/tests/metainfo/test_mongodb_extension.py b/tests/metainfo/test_mongodb_extension.py index 61911d1d14..3f03c65a6d 100644 --- a/tests/metainfo/test_mongodb_extension.py +++ b/tests/metainfo/test_mongodb_extension.py @@ -51,7 +51,7 @@ class A(MSection): d = SubSection(sub_section=D.m_def) -def test_create_new(mongo): +def test_create_new(mongo_function): a = A() a.primary_id = '123' a.not_in_mongo = 'not_in_mongo' @@ -119,7 +119,7 @@ def test_update_self(): assert a_from_db.value2 == 3 -def test_annotations(mongo): +def test_annotations(mongo_function): """Test that non-annotated quantities and sections are not stored.""" a = A() a.primary_id = '123' diff --git a/tests/parsing/test_tabular.py b/tests/parsing/test_tabular.py index d37ef3f9dc..29032ba2a7 100644 --- a/tests/parsing/test_tabular.py +++ b/tests/parsing/test_tabular.py @@ -339,7 +339,7 @@ def test_tabular_complex_schema(raw_files_function, monkeypatch, schema): def test_tabular_entry_mode( - mongo, test_user, raw_files_function, monkeypatch, proc_infra + mongo_function, test_user, raw_files_function, monkeypatch, proc_infra ): upload = Upload(upload_id='test_upload_id', main_author=test_user.user_id) upload.save() diff --git a/tests/plugins/perovskite_solar_cell_database/test_perovskite_database.py b/tests/plugins/perovskite_solar_cell_database/test_perovskite_database.py index 23a4dd81e7..93b7b7265d 100644 --- a/tests/plugins/perovskite_solar_cell_database/test_perovskite_database.py +++ b/tests/plugins/perovskite_solar_cell_database/test_perovskite_database.py @@ -23,7 +23,7 @@ from nomad.utils.exampledata import ExampleData def test_perovskite_solar_cell_plugin_processing( - raw_files_function, no_warn, test_user, mongo + raw_files_function, no_warn, test_user, mongo_function ): directory = 'tests/data/plugins/perovskite_solar_cell_database' mainfile = 'example.archive.json' diff --git a/tests/processing/test_base.py b/tests/processing/test_base.py index c327a41b11..6648459420 100644 --- a/tests/processing/test_base.py +++ b/tests/processing/test_base.py @@ -101,7 +101,7 @@ class SimpleProc(Proc): @pytest.mark.parametrize( 'with_args', [pytest.param(False, id='no-args'), pytest.param(True, id='with-args')] ) -def test_simple_process(worker, mongo, no_warn, with_args): +def test_simple_process(worker, mongo_function, no_warn, with_args): p = SimpleProc.create() if with_args: process = 'a_process_with_arguments' @@ -128,7 +128,7 @@ class FailingProc(Proc): _ = 1 / 0 -def test_failing_process(worker, mongo, with_error): +def test_failing_process(worker, mongo_function, with_error): p = FailingProc.create() event = 'process failed with exception' @@ -151,7 +151,7 @@ class ProcTwice(Proc): pass -def test_process_twice(worker, mongo, no_warn): +def test_process_twice(worker, mongo_function, no_warn): p = ProcTwice.create() p.process() p.block_until_complete() @@ -382,7 +382,9 @@ class ParentProc(Proc): ), ], ) -def test_parent_child(worker, mongo, reset_events, spawn_kwargs, expected_events): +def test_parent_child( + worker, mongo_function, reset_events, spawn_kwargs, expected_events +): child_args = spawn_kwargs.get('child_args', []) join_args = spawn_kwargs.get('join_args', []) fail_spawn = spawn_kwargs.get('fail_spawn', False) @@ -418,7 +420,7 @@ def test_parent_child(worker, mongo, reset_events, spawn_kwargs, expected_events assert_events(expected_events) -def test_queueing(worker, mongo, reset_events): +def test_queueing(worker, mongo_function, reset_events): p = ParentProc.create(parent_id='p') expected_events = [] # Schedule 20 calls @@ -438,7 +440,7 @@ def test_queueing(worker, mongo, reset_events): assert_events(expected_events) -def test_queueing_failure(worker, mongo, reset_events): +def test_queueing_failure(worker, mongo_function, reset_events): p = ParentProc.create(parent_id='p') # Schedule 20 calls, the second should fail for i in range(20): @@ -464,7 +466,7 @@ def test_queueing_failure(worker, mongo, reset_events): ) -def test_non_blocking_then_blocking(worker, mongo, reset_events): +def test_non_blocking_then_blocking(worker, mongo_function, reset_events): p = ParentProc.create(parent_id='p') p.spawn(delay=1.0) p.blocking() @@ -482,7 +484,7 @@ def test_non_blocking_then_blocking(worker, mongo, reset_events): ) -def test_blocking_then_non_blocking(worker, mongo, reset_events): +def test_blocking_then_non_blocking(worker, mongo_function, reset_events): p = ParentProc.create(parent_id='p') p.blocking(delay=1.0) with pytest.raises(ProcessAlreadyRunning): @@ -492,7 +494,7 @@ def test_blocking_then_non_blocking(worker, mongo, reset_events): assert_events(['p:blocking:start', 'p:blocking:succ']) -def test_local_blocked(worker, mongo, reset_events): +def test_local_blocked(worker, mongo_function, reset_events): p = ParentProc.create(parent_id='p') def other_call(): @@ -512,7 +514,7 @@ def test_local_blocked(worker, mongo, reset_events): assert_events(['p:non_blocking:start', 'other_call:blocked', 'p:non_blocking:succ']) -def test_local_blocking(worker, mongo, reset_events): +def test_local_blocking(worker, mongo_function, reset_events): p = ParentProc.create(parent_id='p') def other_call(): @@ -542,7 +544,7 @@ def test_local_blocking(worker, mongo, reset_events): ) -def test_local_failed(worker, mongo, reset_events): +def test_local_failed(worker, mongo_function, reset_events): p = ParentProc.create(parent_id='p') try: p.local_process(fail=True) diff --git a/tests/processing/test_data.py b/tests/processing/test_data.py index 8506f5c0d0..1be228edaa 100644 --- a/tests/processing/test_data.py +++ b/tests/processing/test_data.py @@ -118,7 +118,7 @@ def test_send_mail(mails, monkeypatch): @pytest.fixture(scope='function', autouse=True) -def mongo_forall(mongo): +def mongo_forall(mongo_function): pass @@ -1179,7 +1179,7 @@ def test_skip_matching(proc_infra, test_user): ], ) def test_upload_context( - raw_files_function, mongo, test_user, url, normalized_url, monkeypatch + raw_files_function, mongo_function, test_user, url, normalized_url, monkeypatch ): monkeypatch.setattr( 'nomad.utils.generate_entry_id', lambda *args, **kwargs: 'test_id' diff --git a/tests/test_cli.py b/tests/test_cli.py index dfd6c58d18..9e0cc7f7ed 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -353,7 +353,7 @@ class TestAdminUploads: assert entry.process_status == expected_state @pytest.mark.parametrize('indexed', [True, False]) - def test_integrity_entry_index(self, test_user, mongo, elastic, indexed): + def test_integrity_entry_index(self, test_user, mongo_function, elastic, indexed): data = ExampleData(main_author=test_user) data.create_upload(upload_id='test_upload') data.create_entry(upload_id='test_upload') diff --git a/tests/test_doi.py b/tests/test_doi.py index 94156d084d..a102cf664c 100644 --- a/tests/test_doi.py +++ b/tests/test_doi.py @@ -21,20 +21,20 @@ import pytest from unittest.mock import MagicMock -def test_create(mongo, test_user, no_warn): +def test_create(mongo_function, test_user, no_warn): doi = DOI.create('the_title', test_user) assert DOI.objects(doi=doi.doi).first() is not None assert doi.metadata_xml is not None -def test_create_doi_counter(mongo, test_user, no_warn): +def test_create_doi_counter(mongo_function, test_user, no_warn): DOI.create('the_title', test_user) doi = DOI.create('the_title', test_user) assert doi.doi.endswith('-2') -def test_create_draft_doi(mongo, test_user, no_warn): +def test_create_draft_doi(mongo_function, test_user, no_warn): if config.datacite.enabled: doi = DOI.create('the_title', test_user) doi.create_draft() @@ -52,7 +52,7 @@ def test_create_draft_doi(mongo, test_user, no_warn): ], ) def test_datacite_requests( - mongo, monkeypatch, test_user, status_code, response_ok, is_findable, text + mongo_function, monkeypatch, test_user, status_code, response_ok, is_findable, text ): if config.datacite.enabled: -- GitLab