Skip to content

Commit

Permalink
Create new butler for each ingest test
Browse files Browse the repository at this point in the history
The order the tests ran could lead to errors where a previous
test has already defined an exposure record. A new butler has
to be created each time to ensure that there is a clean slate
of exposure dimension records regardless of test order.
  • Loading branch information
timj committed Apr 29, 2024
1 parent e11b65d commit b2c62a4
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions tests/test_ingest.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,25 +92,22 @@ class RawIngestImpliedIndexTestCase(RawIngestTestCase):


class RawIngestEdgeCaseTestCase(unittest.TestCase):
"""Test ingest using non-standard approaches including failures."""
"""Test ingest using non-standard approaches including failures.
@classmethod
def setUpClass(cls):
Must create a new butler for each test because dimension records are
globals.
"""

def setUp(self):
butlerConfig = """
datastore:
# Want to ingest real files so can't use in-memory datastore
cls: lsst.daf.butler.datastores.fileDatastore.FileDatastore
"""
cls.root = tempfile.mkdtemp(dir=TESTDIR)
cls.creatorButler = butlerTests.makeTestRepo(cls.root, {}, config=Config.fromYaml(butlerConfig))
DummyCam().register(cls.creatorButler.registry)

@classmethod
def tearDownClass(cls):
if cls.root is not None:
shutil.rmtree(cls.root, ignore_errors=True)
self.root = tempfile.mkdtemp(dir=TESTDIR)
self.creatorButler = butlerTests.makeTestRepo(self.root, {}, config=Config.fromYaml(butlerConfig))
DummyCam().register(self.creatorButler.registry)

def setUp(self):
self.butler = butlerTests.makeTestCollection(self.creatorButler, uniqueId=self.id())
self.outputRun = self.butler.run

Expand All @@ -122,6 +119,10 @@ def setUp(self):
self.good_file = os.path.join(INGESTDIR, "sidecar_data", "dataset_2.yaml")
self.bad_instrument_file = os.path.join(TESTDIR, "data", "calexp.fits")

def tearDown(self):
if self.root is not None:
shutil.rmtree(self.root, ignore_errors=True)

def testSimpleIngest(self):
# Use the default per-instrument run for this.
self.task.run([self.good_file])
Expand Down

0 comments on commit b2c62a4

Please sign in to comment.