# Cleaning up and removing a collection

**URL:** <https://www.rubin.community/t/cleaning-up-and-removing-a-collection/6907>\
**Category:** Support\
**Created:** [July 20, 2022, 9:12am UTC](https://www.rubin.community/t/cleaning-up-and-removing-a-collection/6907 "2022-07-20T09:12:55Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![petarz](https://avatars.discourse-cdn.com/v4/letter/p/f19dbf/32.png) [@petarz](https://www.rubin.community/u/petarz)\
**Post date:** [July 20, 2022, 9:12am UTC](https://www.rubin.community/t/cleaning-up-and-removing-a-collection/6907/1 "2022-07-20T09:12:55Z")

</div>

Hi, I would like to create a unit test using Butler which involves creating some things in a temporary collection and then removing the collection once the test is done. But I have trouble removing a collection. What would be a proper procedure for cleaning it up and removing? Can someone provide some sample code?

Thanks

---

<div class="post-metadata">

**Author:** ![timj](https://sea2.discourse-cdn.com/flex002/user_avatar/www.rubin.community/timj/32/10_2.png) [@timj](https://www.rubin.community/u/timj)\
**Post date:** [July 20, 2022, 12:08pm UTC](https://www.rubin.community/t/cleaning-up-and-removing-a-collection/6907/2 "2022-07-20T12:08:04Z")

</div>

Are you testing with a Butler that has existing content in it? Most of our testing is with smaller Butler repositories that are either constructed from a testdata package with the data and an exported YAML file (see pipelines\_check package), or have a small Butler SQLite registry committed to git. Regardless we clean up everything after the testing and nothing needs to see the new run collection.

If you have a large shared butler that you want to run unit tests from then your best bet is for the unit test to create a local butler and use `Butler.transfer_from()` to copy over just the datasets you need (if your main repo is using a POSIX datastore then transfer with symlinks will be fine). Then you run your tests in that local SQLite registry using a temp directory as datastore and delete it when you are done.

---

<div class="post-metadata">

**Author:** ![petarz](https://avatars.discourse-cdn.com/v4/letter/p/f19dbf/32.png) [@petarz](https://www.rubin.community/u/petarz)\
**Post date:** [July 20, 2022, 1:04pm UTC](https://www.rubin.community/t/cleaning-up-and-removing-a-collection/6907/3 "2022-07-20T13:04:40Z")

</div>

OK thanks, I’ll read up on transfer\_from()

---

<div class="post-metadata">

**Author:** ![timj](https://sea2.discourse-cdn.com/flex002/user_avatar/www.rubin.community/timj/32/10_2.png) [@timj](https://www.rubin.community/u/timj)\
**Post date:** [July 20, 2022, 1:54pm UTC](https://www.rubin.community/t/cleaning-up-and-removing-a-collection/6907/4 "2022-07-20T13:54:06Z")

</div>

You will need to use w.2022.30 (or a recent daily) to get the usable version of `Butler.transfer_from()` that also copies dimension records across. That should be published tonight.

---

<div class="post-metadata">

**Author:** ![timj](https://sea2.discourse-cdn.com/flex002/user_avatar/www.rubin.community/timj/32/10_2.png) [@timj](https://www.rubin.community/u/timj)\
**Post date:** [July 20, 2022, 1:57pm UTC](https://www.rubin.community/t/cleaning-up-and-removing-a-collection/6907/5 "2022-07-20T13:57:44Z")

</div>

I will add that it is of course possible to call `removeRuns()` as part of a test cleanup but it’s entirely possible you will end up with something failing where call `shutil.rmtree()` on a temp dir is going to be much more reliable. If you do end up using collections in your main repo, you might want to adopt a standardized naming scheme for your collections so you can run a clean up script outside of the test environment to pick up any leftovers.

---

<div class="post-metadata">

**Author:** ![petarz](https://avatars.discourse-cdn.com/v4/letter/p/f19dbf/32.png) [@petarz](https://www.rubin.community/u/petarz)\
**Post date:** [July 20, 2022, 2:32pm UTC](https://www.rubin.community/t/cleaning-up-and-removing-a-collection/6907/6 "2022-07-20T14:32:46Z")

</div>

I see, thanks
