python-nose

testing python multiprocessing pool code with nose

為{幸葍}努か 提交于 2019-12-08 21:44:33
问题 I am trying to write tests with nose that get set up with something calculated using multiprocessing. I have this directory structure: code/ tests/ tests.py tests.py looks like this: import multiprocessing as mp def f(i): return i ** 2 pool = mp.Pool() out = pool.map(f, range(10)) def test_pool(): """Really simple test that relies on the output of pool.map. The actual tests are much more complicated, but this is all that is needed to produce the problem.""" ref_out = map(f, range(10)) assert

How to organize python test in a way that I can run all tests in a single command?

馋奶兔 提交于 2019-12-04 17:33:40
问题 Currently my code is organized in the following tree structure: src/ module1.py module2.py test_module1.py test_module2.py subpackage1/ __init__.py moduleA.py moduleB.py test_moduleA.py test_moduleB.py Where the module*.py files contains the source code and the test_module*.py contains the TestCase s for the relevant module. With the following comands I can run the tests contained in a single file, for example: $ cd src $ nosetests test_filesystem.py .................. -----------------------

How to assert output with nosetest/unittest in python?

半腔热情 提交于 2019-11-26 23:49:24
I'm writing tests for a function like next one: def foo(): print 'hello world!' So when I want to test this function the code will be like this: import sys from foomodule import foo def test_foo(): foo() output = sys.stdout.getline().strip() # because stdout is an StringIO instance assert output == 'hello world!' But if I run nosetests with -s parameter the test crashes. How can I catch the output with unittest or nose module? Rob Kennedy I use this context manager to capture output. It ultimately uses the same technique as some of the other answers by temporarily replacing sys.stdout . I

How to assert output with nosetest/unittest in python?

淺唱寂寞╮ 提交于 2019-11-26 08:49:27
问题 I\'m writing tests for a function like next one: def foo(): print \'hello world!\' So when I want to test this function the code will be like this: import sys from foomodule import foo def test_foo(): foo() output = sys.stdout.getline().strip() # because stdout is an StringIO instance assert output == \'hello world!\' But if I run nosetests with -s parameter the test crashes. How can I catch the output with unittest or nose module? 回答1: I use this context manager to capture output. It