Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have such structure

app/
    __init__.py
    phonebook.py
    test_phonebook.py

Being in app directory I can run tests in terminal with python test_phonebook.py

But why tests do not run when I enterpython -m unittest being in app directory? I see message that 0 tests run

share|improve this question

1 Answer 1

up vote 0 down vote accepted

If you want to run multiple test_*.py files by hand, you have to create unittest.TestLoader to select tests and run that with unittest.TestRunner.

For example you can add __main__.py to your app

import unittest
import os
def run(verbosity=2):
    suite = unittest.TestLoader().discover(os.path.dirname(__file__))
    unittest.TextTestRunner(verbosity=verbosity).run(suite)
run()

and launch it with

$>python -m app

So it will discover all your tests inside app and launch them.

share|improve this answer
    
looks like hack, if there a cleaner solution? –  micgeronimo Jan 21 at 21:42
    
Its the way unittest intended to be used, according to unittest docs. And i dont know about 'cleaner' but its a pythonic way, because Explicit is better than implicit –  denz Jan 22 at 15:52

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.