nosetests

How to use nose's assert_raises?

a 夏天 提交于 2019-11-28 23:34:32
问题 I've searched for documentation, but couldn't find any. There were a couple that didn't explain much. Can someone explain to me Nose's assert_raises(what should I put here?) function and how to use it? 回答1: The assert_raises() function tests to make sure a function call raises a specified exception when presented with certain parameters. For example, if you had a function add that adds two numbers, it should probably raise a TypeError when you pass it, say, an integer and a string. So: from

nosetests is capturing the output of my print statements. How to circumvent this?

别等时光非礼了梦想. 提交于 2019-11-28 15:50:15
When I type $ nosetests -v mytest.py all my print outputs are captured when all tests pass. I want to see print outputs even everything passes. So what I'm doing is to force an assertion error to see the output, like this. class MyTest(TestCase): def setUp(self): self.debug = False def test_0(self): a = .... # construct an instance of something # ... some tests statements print a.dump() if self.debug: eq_(0,1) It feels so hackish, there must be a better way. Enlighten me please. Either: $ nosetests --nocapture mytest.py Or: $ NOSE_NOCAPTURE=1 nosetests mytests.py (it can also be specified in

Disabling Python nosetests

给你一囗甜甜゛ 提交于 2019-11-28 06:42:10
When using nosetests for Python it is possible to disable a unit test by setting the test function's __test__ attribute to false. I have implemented this using the following decorator: def unit_test_disabled(): def wrapper(func): func.__test__ = False return func return wrapper @unit_test_disabled def test_my_sample_test() #code here ... However, this has the side effect of calling wrapper as the unit test. Wrapper will always pass but it is included in nosetests output. Is there another way of structuring the decorator so that the test will not run and does not appear in nosetests output. I

nosetests is capturing the output of my print statements. How to circumvent this?

☆樱花仙子☆ 提交于 2019-11-27 09:35:55
问题 When I type $ nosetests -v mytest.py all my print outputs are captured when all tests pass. I want to see print outputs even everything passes. So what I'm doing is to force an assertion error to see the output, like this. class MyTest(TestCase): def setUp(self): self.debug = False def test_0(self): a = .... # construct an instance of something # ... some tests statements print a.dump() if self.debug: eq_(0,1) It feels so hackish, there must be a better way. Enlighten me please. 回答1: Either:

Disabling Python nosetests

最后都变了- 提交于 2019-11-27 01:27:18
问题 When using nosetests for Python it is possible to disable a unit test by setting the test function's __test__ attribute to false. I have implemented this using the following decorator: def unit_test_disabled(): def wrapper(func): func.__test__ = False return func return wrapper @unit_test_disabled def test_my_sample_test() #code here ... However, this has the side effect of calling wrapper as the unit test. Wrapper will always pass but it is included in nosetests output. Is there another way

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