Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to get python's nose module to work the same in __main__ and on the command line?

I'm not sure of how to get the nose module's __main__ handler to work. I have this at the end of my test module:

if __name__ == "__main__":
    import nose
    nose.main()

Which gives me:

----------------------------------------------------------------------
Ran 0 tests in 0.002s

OK

but it I run the same thing via the command line, it finds the tests and executes them:

MacBook-Pro:Storage_t meloam$nosetests FileManager_t.py 
............E..
======================================================================
ERROR: testStageOutMgrWrapperRealCopy (WMCore_t.Storage_t.FileManager_t.TestFileManager)
----------------------------------------------------------------------

SNIP

----------------------------------------------------------------------
Ran 15 tests in 0.082s

FAILED (errors=1)

I've been playing with passing different arguments to nose.main() but I can't find anything that works. Am I missing something really obvious?

Thanks

like image 549
PerilousApricot Avatar asked Jul 01 '10 18:07

PerilousApricot


People also ask

Which command is used to run nose tests?

nose can be integrated with DocTest by using with-doctest option in athe bove command line. The result will be true if the test run is successful, or false if it fails or raises an uncaught exception. nose supports fixtures (setup and teardown methods) at the package, module, class, and test level.

What is nose used for in Python?

Nose is a popular test automation framework in Python that extends unittest to make testing easier. The other advantages of using the Nose framework are the enablement of auto discovery of test cases and documentation collection.


1 Answers

For posterity's sake, this is what I use:

if __name__ == '__main__':
    import nose
    nose.run(argv=[__file__, '--with-doctest', '-vv'])

The --with-doctests will also execute your doctests in the same file.

like image 199
Daniel Werner Avatar answered Nov 05 '22 04:11

Daniel Werner