Skip to content

Commit

Permalink
still trying to figure out which test is leaving provenances behind i…
Browse files Browse the repository at this point in the history
…n the database
  • Loading branch information
rknop committed Jul 30, 2024
1 parent 18defea commit 97a6f8c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 20 deletions.
20 changes: 17 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down Expand Up @@ -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
Expand Down
11 changes: 0 additions & 11 deletions tests/models/test_zero_point.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 8 additions & 6 deletions util/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 97a6f8c

Please sign in to comment.