[AstroPy] Using test classes with astropy testing framework
Christoph Deil
deil.christoph at googlemail.com
Thu May 7 09:52:03 EDT 2015
> On 07 May 2015, at 15:47, Andrew Hearin <andrew.hearin at yale.edu> wrote:
>
> Hi everyone,
>
> I’m using the Astropy package template to develop a package, and have thus far had an entirely painless experience building a test suite using the py.test settings that come pre-configured with the template. However, I am now trying to use python classes to construct a series of tests, and for some (almost undoubtedly simple) reason, py.test is not detecting my tests that appear within a class.
>
> In the following example, I have done my best to match the pattern used in the test_representation module that appears in the coordinates sub-package of astropy:
>
>
> def trivial_test():
> assert 42 == 42
>
> class DummyTestClass(object):
>
> def dummy_test(self):
> assert 42 == 43
>
>
> Ok, so that’s my setup. Now here’s the problem. When I run "python setup.py test” from my sub-package root directory, the testing module in which the above code appears does indeed execute, but the result only registers as “1 passed”, rather than “1 failed, 1 passed”, meaning that dummy_test is not executing.
>
> How should I modify my test suite to run tests that are embedded in classes? In the examples I have looked at online, all of them seem to use a __main__ execution, but Astropy testing does not seem to proceed this way, and I would rather do what y’all do.
>
> Cheers,
> Andrew
> _______________________________________________
> AstroPy mailing list
> AstroPy at scipy.org
> http://mail.scipy.org/mailman/listinfo/astropy
You have to follow the pytest conventions for test discovery:
http://pytest.org/latest/goodpractises.html#conventions-for-python-test-discovery <http://pytest.org/latest/goodpractises.html#conventions-for-python-test-discovery>
I.e. start functions with `test_` and classes with `Test`.
This works:
def test_trivial():
assert 42 == 42
class TestDummyClass(object):
def test_dummy(self):
assert 42 == 43
Christoph
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/astropy/attachments/20150507/6a6ec228/attachment.html>
More information about the AstroPy
mailing list