3

I have written a unittest of a program MachineSettings_test.py of mine of the following form:

import unittest
import MachineSettings as MS
class TestMachineSettings(unittest.TestCase):
 def setUp(self):
 [...]
 def testStringRepresentation(self):
 [...]
 def testCasDict(self):
 [...]
if __name__=="__main__":
 unittest.main()

I am a little bit confused by the following fact: If I run

python -m unittest -v MachineSettings_test

I get as output

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

i.e. Python does not recognize the tests inside the unittesting module.

But if I just run

python MachineSettings_test.py

Everything works fine and I get as output

..
----------------------------------------------------------------------
Ran 2 tests in 0.000s
OK

This is confusing to me and I could not find any similar question here yet, so I posted it.

The version of Python that I am (forced to be) using is 2.6, but I could not find anything in the documentation that makes this case to be special.

Anyone an idea?

Thanks

asked Apr 25, 2013 at 15:52

1 Answer 1

4

From the documentation:

Changed in version 2.7: In earlier versions it was only possible to run individual test methods and not modules or classes.

And you're trying to run tests for whole modules with python 2.6.

Apparently you can't even run from individual test methods with -m unittest in python 2.6. See this question for details.

You might wanna try nose or nose2.

answered Apr 25, 2013 at 15:54
Sign up to request clarification or add additional context in comments.

4 Comments

How does that answer the question?
He's using 2.6 and wants to run python -m unittest -v MachineSettings_test, i.e. on a module.
Oh, right. (You might want to point that out in the answer as well.)
Jup, that was the answer that I was searching for. Sorry, I totally oversaw that line in the documentation. Thanks for that!

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.