468,287 Members | 1,999 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,287 developers. It's quick & easy.

problem including tests in unittest

I have a module for which I am trying to code a unit test. However,
when I run unittest.main(), I get:

In [1]: import PyMC

In [2]: PyMC.unittest.main()

----------------------------------------------------------------------
Ran 0 tests in 0.000s

OK
This is confusing, because I have set up a class called MCMCTest that
is a sublcass of unttest.TestCase, which in turn contains a test
method. Yet, unittest seems not to be aware of it. Is there anything I
am forgetting?

Thanks,
Chris

--
Chris Fonnesbeck + Atlanta, GA + http://trichech.us
Oct 12 '06 #1
1 3686
Chris Fonnesbeck wrote:
I have a module for which I am trying to code a unit test. However,
when I run unittest.main(), I get:

In [1]: import PyMC

In [2]: PyMC.unittest.main()

----------------------------------------------------------------------
Ran 0 tests in 0.000s

OK
This is confusing, because I have set up a class called MCMCTest that
is a sublcass of unttest.TestCase, which in turn contains a test
method. Yet, unittest seems not to be aware of it. Is there anything I
am forgetting?
By default unittest.main() scans the __main__ module for TestCases.
Though you could use it from an interactive interpreter
>>import unittest
unittest.main("PyMC", argv=["yadda", "-v"])
test_alpha (PyMC.Test) ... ok
test_beta (PyMC.Test) ... ok

----------------------------------------------------------------------
Ran 2 tests in 0.000s

OK
$ # Oops

without countermeasures unittest.main() will exit that too after completion.
The normal usage (the only one I know) is to put it inside the test script:

# your testcases
if __name__ == "__main__":
unittest.main()

and run that from the shell:

$ python PyMC.py -v
test_alpha (__main__.Test) ... ok
test_beta (__main__.Test) ... ok

----------------------------------------------------------------------
Ran 2 tests in 0.001s

OK

Peter
Oct 12 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

12 posts views Thread by Paul Moore | last post: by
7 posts views Thread by Jorgen Grahn | last post: by
1 post views Thread by travislspencer | last post: by
2 posts views Thread by Ben Finney | last post: by
6 posts views Thread by Ben Finney | last post: by
5 posts views Thread by alainpoint | last post: by
1 post views Thread by Pupeno | last post: by
1 post views Thread by jimburton | last post: by
reply views Thread by Roy Smith | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.