# Choosing a Python test framework

**URL:** <https://www.rubin.community/t/choosing-a-python-test-framework/279>\
**Category:** Data Management\
**Tags:** square, dm-dev\
**Created:** [October 7, 2015, 3:48am UTC](https://www.rubin.community/t/choosing-a-python-test-framework/279 "2015-10-07T03:48:01Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jsick](https://sea2.discourse-cdn.com/flex002/user_avatar/www.rubin.community/jsick/32/672_2.png) [@jsick](https://www.rubin.community/u/jsick)\
**Post date:** [October 7, 2015, 3:48am UTC](https://www.rubin.community/t/choosing-a-python-test-framework/279/1 "2015-10-07T03:48:02Z")

</div>

First of all, we clearly need a _real_ test framework to run our `unittest` unit tests. @timj has been experimenting with [nose](https://nose.readthedocs.org/en/latest/), which is used by numpy, but I also know that [py.test](http://pytest.org/latest/) is a newer entry in the market. On the surface, both seen very similar, so it’s hard to tell which is better. So I asked the community what they like to use, and this is what I got:

[https://storify.com/jonathansick/astronomers-py-test](https://storify.com/jonathansick/astronomers-py-test)

So needless to say, all whole-hearted recommendations for py.test.

I think Erik Tollerud’s email [on the astropy-dev mailing list](https://mail.scipy.org/pipermail/astropy/2011-July/001673.html) sums up the technical choice well:

- we’d be happy with both nose or py.test for basic functionality
- py.test has a better plugin architecture, so we (SQuaRE and friends) would likely be much happier if we were writing our own plugins against py.test.
- py.test and nose are largely compatible in terms of the tests they run when we’re using them in a basic sense, so we can even try both initially if we _really_ wanted
- [nose development is cooling off](https://github.com/nose-devs/nose/pulse/monthly) while [py.test has an extremely active development and user community](https://github.com/pytest-dev/pytest/pulse/monthly).

Generally speaking, the modern astro python community is backing py.test. Overall, py.test is the best framework to invest in.

---

<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:** [October 7, 2015, 3:53am UTC](https://www.rubin.community/t/choosing-a-python-test-framework/279/2 "2015-10-07T03:53:33Z")

</div>

I’m perfectly okay with switching to py.test. It wouldn’t hurt to try both initially and ensure that we get the same failure modes when we port things over.

---

<div class="post-metadata">

**Author:** ![jsick](https://sea2.discourse-cdn.com/flex002/user_avatar/www.rubin.community/jsick/32/672_2.png) [@jsick](https://www.rubin.community/u/jsick)\
**Post date:** [October 7, 2015, 3:59am UTC](https://www.rubin.community/t/choosing-a-python-test-framework/279/3 "2015-10-07T03:59:06Z")

</div>

To get a sense or real-world usage of py.test, here’s the astropy sub-package with their py.test plugins and test running wrappers:

> **[astropy/astropy](https://github.com/astropy/astropy/tree/master/astropy/tests)**
>
> Repository for the Astropy core package. Contribute to astropy/astropy development by creating an account on GitHub.

---

<div class="post-metadata">

**Author:** ![swinbank](https://sea2.discourse-cdn.com/flex002/user_avatar/www.rubin.community/swinbank/32/24_2.png) [@swinbank](https://www.rubin.community/u/swinbank)\
**Post date:** [October 8, 2015, 2:43pm UTC](https://www.rubin.community/t/choosing-a-python-test-framework/279/4 "2015-10-08T14:43:22Z")

</div>

What I’ve not seen – either in the above or in previous discussions – is a straightforward enumeration of our requirements from a test framework. I understand that the ability to produce xUnit output which can be ingested by Jenkins is important, but is there anything else?

My own feeling is that the “activation energy” for requiring our developers and contributors to learn a new, non-standard-library, test (or, indeed, anything) framework should be quite high: I’d like to see a really concrete discussion of what we’re buying into.

---

<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:** [October 8, 2015, 3:48pm UTC](https://www.rubin.community/t/choosing-a-python-test-framework/279/5 "2015-10-08T15:48:31Z")

</div>

> [@jdswinbank](#):
>
> equiring our developers and contributors to learn a new, non-standard-library

My opening position here is that I’m not asking for any move away from the `unittest` approach to testing. To start with `py.test` or `nose` would just be used for driving the tests and gathering the output. I’m not worrying about using py.test-specific features to begin with and that is not driving this change.

The reason tests have to change is because the tests are not actually compliant with the `unittest` philosophy in many cases. In particular the way tests are skipped differs wildly from test to test and only occasionally are tests skipped properly. Furthermore the use of suites is not compatible with test drivers that automatically determine which tests are present and removing those is a side effect of the work.

The other outcome of using a test driver is that the tests tend to run in a different namespace (not ` __main__ `) and some tests seem to misbehave when they are not run in a separate process (the SIP fitting in `meas_astrom` has that problem). We probably don’t want tests that fail simply because some other code has run first so these occurrences worry me and need to be examined further.

The memory test case seems to be important and it is relatively easy to make it trigger without using an explicit suite. This doesn’t mean we will like the results though.

I have an exploratory ticket on this in [DM-3901](https://jira.lsstcorp.org/browse/DM-3901).
