nose

Interactive debugging with nosetests in PyDev

廉价感情. 提交于 2019-11-30 03:51:42
问题 I'm using PyDev ( with Aptana ) to write and debug a Python Pylons app, and I'd like to step through the tests in the debugger. Is it possible to launch nosetests through PyDev and stop at breakpoints? 回答1: Here is what i do to run nosetests using eclipse Pydev (Hope this will help you). first of all i create a python script and i put it in the root of my package directory : --Package | | -- runtest.py | | -- ... (others modules) and in runtest.py i put: import nose nose.main() now i go to in

Getting nose to ignore a function with 'test' in the name

本小妞迷上赌 提交于 2019-11-30 02:16:59
问题 The nose discovery process finds all modules whose name starts with test , and within them all functions which have test in the name and tries to run them as unit tests. See http://nose.readthedocs.org/en/latest/man.html I have a function whose name is say, make_test_account , in the file accounts.py . I want to test that function in a test module called test_account . So at the start of that file I do: from foo.accounts import make_test_account But now I find that nose treats the function

How to exclude mock package from python coverage report using nosetests

六月ゝ 毕业季﹏ 提交于 2019-11-30 01:27:11
I currently try to use the mock library to write some basic nose unittests in python. After finishing some basic example I now tried to use nosetests --with-coverage and now I have the mock package and the package I tried to 'mock away' are shown in the coverage report. Is there a possibility to exclude these? Here is the class I want to test: from imaplib import IMAP4 class ImapProxy: def __init__(self, host): self._client = IMAP4(host) And the testcase: from mock import patch from ImapProxy import ImapProxy class TestImap: def test_connect(self): with patch('ImapProxy.IMAP4') as imapMock:

How to automatically run tests when there's any change in my project (Django)?

扶醉桌前 提交于 2019-11-30 01:14:24
At the moment I am running python manage.py test every once in a while after I make significant changes in my django project. Is it possible to run those tests automatically whenever I change and save a file in my project? It'll be useful to detect bugs earlier (I know rails has something like this with rspec). I am using nose and django-nose. Thanks in advance. Use entr : $ find . -name '*.py' | entr python ./manage.py test Or, for extra credit, combine it with ack : $ ack --python | entr python ./manage.py test If you want it to even find new files as you add them: $ until ack -f --python |

Mocking two functions with patch for a unit test

余生颓废 提交于 2019-11-30 01:09:51
I have a function I want to unit test contains calls two other functions. I am unsure how can I mock both functions at the same time properly using patch. I have provided an example of what I mean below. When I run nosetests, the tests pass but I feel that there must be a cleaner way to do this and I do not really Understand the piece regarding f.close()... The directory structure looks like this: program/ program/ data.py tests/ data_test.py data.py: import cPickle def write_out(file_path, data): f = open(file_path, 'wb') cPickle.dump(data, f) f.close() data_test.py: from mock import

Problems using nose in a virtualenv

左心房为你撑大大i 提交于 2019-11-29 22:49:11
I am unable to use nose (nosetests) in a virtualenv project - it can't seem to find the packages installed in the virtualenv environment. The odd thing is that i can set test_suite = 'nose.collector' in setup.py and run the tests just fine as python setup.py test but when running nosetests straight, there are all sorts of import errors. I've tried it with both a system-wide installation of nose and a virtualenv nose package and no luck. Any thoughts? Thanks!! Are you able to run myenv/bin/python /usr/bin/nosetests ? That should run Nose using the virtual environment's library set. You need to

How should I verify a log message when testing Python code under nose?

早过忘川 提交于 2019-11-29 22:04:24
I'm trying to write a simple unit test that will verify that, under a certain condition, a class in my application will log an error via the standard logging API. I can't work out what the cleanest way to test this situation is. I know that nose already captures logging output through it's logging plugin, but this seems to be intended as a reporting and debugging aid for failed tests. The two ways to do this I can see are: Mock out the logging module, either in a piecemeal way (mymodule.logging = mockloggingmodule) or with a proper mocking library. Write or use an existing nose plugin to

nosetests with tensorflow: lots of debugging output, how to disable

笑着哭i 提交于 2019-11-29 19:15:37
问题 When I use nosetests with some test scripts with TensorFlow, I get's lots of debugging output from TensorFlow: az@azmacbookpro ~/P/crnn> nosetests tests/test_TFUtil.py Level 1:tensorflow:Registering FakeQuantWithMinMaxArgs (<function _FakeQuantWithMinMaxArgsGradient at 0x112306048>) in gradient. Level 1:tensorflow:Registering FakeQuantWithMinMaxVars (<function _FakeQuantWithMinMaxVarsGradient at 0x1126ba9d8>) in gradient. Level 1:tensorflow:Registering FakeQuantWithMinMaxVarsPerChannel (

Python unittest: cancel all tests if a specific test fails

你。 提交于 2019-11-29 14:02:53
问题 I am using unittest to test my Flask application, and nose to actually run the tests. My first set of tests is to ensure the testing environment is clean and prevent running the tests on the Flask app's configured database. I'm confident that I've set up the test environment cleanly, but I'd like some assurance of that without running all the tests. import unittest class MyTestCase(unittest.TestCase): def setUp(self): # set some stuff up pass def tearDown(self): # do the teardown pass class

Read nose tests arguments in a file especially @attr

穿精又带淫゛_ 提交于 2019-11-29 11:57:14
If I invoke a test script say nosetests -a tag1='one' is there a way to print the user input of tag1 in my script? @attr(tag1=['one', 'two', 'three', 'four']) def test_real_logic(self): #how to print the user input here Not without some pain. self.test_real_logic.tag1 should give you all the attributes attached to the function. They are stored as a dictionary within __dict__ attribute of the test function. For test_real_logic.tag1 it would be ['one', 'two', 'three', 'four']. If you do not want to hard code function name, you cad try extract the dictionary by doing something like: import sys