From 97a6f8c287509daf27393155c0e1b1b099ca9362 Mon Sep 17 00:00:00 2001 From: Rob Knop Date: Tue, 30 Jul 2024 07:43:28 -0700 Subject: [PATCH] still trying to figure out which test is leaving provenances behind in the database --- tests/conftest.py | 20 +++++++++++++++++--- tests/models/test_zero_point.py | 11 ----------- util/cache.py | 14 ++++++++------ 3 files changed, 25 insertions(+), 20 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 1bd2fef2..6bc3c636 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -34,8 +34,8 @@ # at the end of tests. In general, we want this to be True, so we can make sure # that our tests are properly cleaning up after themselves. However, the errors # from this can hide other errors and failures, so when debugging, set it to False. -verify_archive_database_empty = True -# verify_archive_database_empty = False +# verify_archive_database_empty = True +verify_archive_database_empty = False pytest_plugins = [ @@ -126,7 +126,21 @@ def any_objects_in_database( dbsession ): # Uncomment this fixture to run the "empty database" check after each # test. This can be useful in figuring out which test is leaving stuff -# behind. +# behind. Because of session scope fixtures, it will cause nearly every +# (or every) test to fail, but at least you'll have enough debug output +# to (hopefully) find the tests that are leaving behind extra stuff. +# +# NOTE -- for this to work, ironically, you have to set +# verify_archive_database_empty to False at the top of this file. +# Otherwise, at the end of all the tests, the things left over in the +# databse you are looking for will cause everything to fail, and you +# *only* get that message instead of all the error messages from here +# that you wanted to get! (Oh, pytest.) +# +# (This is probably not practical, becasuse there is *so much* module +# and session scope stuff that lots of things are left behind by tests. +# You will have to sift through a lot of output to find what you're +# looking for. We need a better way.) @pytest.fixture(autouse=True) def check_empty_database_at_end_of_each_test(): yield True diff --git a/tests/models/test_zero_point.py b/tests/models/test_zero_point.py index 48f8b629..acf2c336 100644 --- a/tests/models/test_zero_point.py +++ b/tests/models/test_zero_point.py @@ -38,17 +38,6 @@ def test_zeropoint_committing(ztf_datastore_uncommitted, provenance_base, proven image.psf.save() image.provenance = provenance_base image.save() - # For some reason, the next image.merge_all line started to - # fail with ZTF not being a known instrument. I'm not sure - # why it would start to fail, and not have failed before, - # but to make it pass, make sure instruments are all - # registered. (Think about if there's a better way to - # register instruments. One would be just to import all the - # instrument classes manually in - # instrument.register_all_instruments().... Inelegant, but - # it woudl work.) - import models.instrument - models.instrument.register_all_instruments() image = image.merge_all(session) zp = ZeroPoint(zp=20.1, dzp=0.1) diff --git a/util/cache.py b/util/cache.py index 82350462..5209080e 100644 --- a/util/cache.py +++ b/util/cache.py @@ -281,12 +281,14 @@ def copy_list_from_cache(cls, cache_dir, filepath): now = datetime.datetime.now( tz=datetime.timezone.utc ) for obj_dict in json_list: newobj = cls.from_dict( obj_dict ) - if hasattr( newobj, 'id' ): - newobj.id = None - if hasattr( newobj, 'created_at' ): - newobj.created_at = now - if hasattr( newobj, 'modified' ): - newobj.modified = now + # COMMENTED THE NEXT OUT. + # Search above for "COMMENTED THE NEXT OUT" for reason. + # if hasattr( newobj, 'id' ): + # newobj.id = None + # if hasattr( newobj, 'created_at' ): + # newobj.created_at = now + # if hasattr( newobj, 'modified' ): + # newobj.modified = now output.append( newobj ) if len(output) == 0: