[AstroPy] Using test classes with astropy testing framework

Andrew Hearin andrew.hearin at yale.edu
Thu May 7 10:03:53 EDT 2015


Thanks, Christoph, that did the trick!



On May 7, 2015, at 9:52 AM, Christoph Deil <deil.christoph at googlemail.com> wrote:

> 
>> 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
> 
> 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
> _______________________________________________
> AstroPy mailing list
> AstroPy at scipy.org
> https://urldefense.proofpoint.com/v2/url?u=http-3A__mail.scipy.org_mailman_listinfo_astropy&d=AwICAg&c=-dg2m7zWuuDZ0MUcV7Sdqw&r=AHkQ8HPUDwzl0x62ybAnwN_OEebPRGDtcjUPBcnLYw4&m=RLWB8rl3RSYWx6Wm8DLb-_R8alZVMzm0vZd1GeWw2EA&s=kxBB-3eJOCFP1EoxxGKLsCMpT_LHmardon2ymwxgaPI&e= 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/astropy/attachments/20150507/71c05a92/attachment.html>


More information about the AstroPy mailing list