diff --git a/tests/app/test_optimade.py b/tests/app/test_optimade.py index 77933d55c2d1c473efa88c335af9e1319241d920..0cbe4a4e513d970ac73d15b0b807957d614a3122 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 9bf3b0814f413c6b724ad4375955f9db434a513e..17172f73faa5987b5662d8dd7ea25a031cce59eb 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 9ae58c840115893b30126ace7368651bea119eb1..edf77153072e66702a211d8bf34a304edce78658 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 19785d725d58b9e653f6ca14f6d263ccf46492dd..56cd1d63530e841a2ca86f3eb790e0c28259f9bd 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 e95a5936583e3c443f5b20cfe019aac291d2b7db..e8cfd1d6f546f723f6102b4a356e8c417083a01d 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 3865d51ba2c7e8800882cd323c0f39057264cc42..e55b4cca7e411e31c9d96dc28b027b24f4479398 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 be68effeafe507d6213d52c5e662518fce9a53d4..c531032542b5b018871162f04b62e04edcbe17ad 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 3d1068e8a70ee070b060676211e9e48cdb53159c..2255a563cab64c7ef9176b8a3a484a99b86a7b90 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 6fe92979016bad51735b910901102e826ab23e6d..22b4be109d52c0a13f68084cef113f8f02dab34d 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 f2c270d03e9188faf802e711f98de8607671f8e1..1da5bfdde3df538f3b59fb00a0e529a9f2caf870 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 b1193c2b0682c0c0d6d64c415e2fbb3ce4cb87ee..7391c86e50ab702d9b757f57a66deab768c1cee6 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 081739850632e9afc8f2196a9ed6146412b4c2b6..ff025eff8e6d11b74b97715497a96cc3ed9aff9c 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 5170f49cbfc99165457c74d512bc3fd44f2168c9..3a9a02874643c7bf1a7148913d18094b81f539c2 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 61911d1d14a5ce4272b0decad3cce3d7bc6010b6..3f03c65a6dc97bb47f92e9532971d2e31d38b5f3 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 d37ef3f9dca9b508341488f259f993a683dd44d2..29032ba2a75160b2223c420d7662cdbff2dac6dd 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 23a4dd81e7de75290e410edad6eb23d54c2b497b..93b7b7265d6fd74a270db34441cdd5fe999da131 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 c327a41b119093726e35ee3f57dff9a18373bea9..664845942043ea7ae64cac96e2d59a5bfc1d5cac 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 8506f5c0d00cf1319cf84d618023d1e9b56c9ef7..1be228edaa47ca8aa5cf623165edfbda033766f8 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 dfd6c58d18c1f96c59c4fb9efe9e87a609b8a158..9e0cc7f7edb4be8a52283a8ced239cd45a4582d0 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 94156d084d933bd8c1a5dbe6f76863d881820e28..a102cf664c2c8e8d5aa1ea3f58c617e1a56e1d17 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: