nosetests

List all Tests Found by Nosetest

醉酒当歌 提交于 2019-11-30 10:45:50
I use nosetests to run my unittests and it works well. I want to get a list of all the tests nostests finds without actually running them. Is there a way to do that? Version 0.11.1 is currently available. You can get a list of tests without running them as follows: nosetests -v --collect-only I recommend using: nosetests -vv --collect-only While the -vv option is not described in man nosetests , "An Extended Introduction to the nose Unit Testing Framework" states that: Using the -vv flag gives you verbose output from nose's test discovery algorithm. This will tell you whether or not nose is

Get IP Address when testing flask application through nosetests

时间秒杀一切 提交于 2019-11-30 08:16:57
My application depends on request.remote_addr which is None when i run tests through nosetests which uses app.test_client().post('/users/login', ....) . How can I emulate an IP (127.0.0.1 works fine) when I run tests? I've tried setting environment variables, sent in headers with the post() method and I've digged through nosetests, werkzeugs and flasks documentation but nothing I've tried has worked. You can set options for the underlying Werkzeug environment using environ_base : from flask import Flask, request import unittest app = Flask(__name__) app.debug = True app.testing = True @app

Excluding abstractproperties from coverage reports

我与影子孤独终老i 提交于 2019-11-30 06:02:51
I have an abstract base class along the lines of: class MyAbstractClass(object): __metaclass__ = ABCMeta @abstractproperty def myproperty(self): pass But when I run nosetests (which coverage) on my project, it complains that the property def line is untested. It can't actually be tested (AFAIK) as instantiation of the abstract class will result in an exception being raised.. Are there any workarounds to this, or do I just have to accept < 100% test coverage? Of course, I could remove the ABCMeta usage and simply have the base class raise NotImpementedError , but I prefer the former method.

How to use nose's assert_raises?

故事扮演 提交于 2019-11-30 02:38:15
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? kindall 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 nose.tools import assert_raises def add(x, y): return x + y assert_raises(TypeError, add, 2, "0") The

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

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

Get IP Address when testing flask application through nosetests

做~自己de王妃 提交于 2019-11-29 11:21:19
问题 My application depends on request.remote_addr which is None when i run tests through nosetests which uses app.test_client().post('/users/login', ....) . How can I emulate an IP (127.0.0.1 works fine) when I run tests? I've tried setting environment variables, sent in headers with the post() method and I've digged through nosetests, werkzeugs and flasks documentation but nothing I've tried has worked. 回答1: You can set options for the underlying Werkzeug environment using environ_base: from

A Nose plugin to specify the order of unit test execution

▼魔方 西西 提交于 2019-11-29 05:47:30
I have a desire to use Nose for an over the wire integration test suite. However, the order of execution of some of these tests is important. That said, I thought I would toss together a quick plugin to decorate a test with the order I want it executed: https://gist.github.com/Redsz/5736166 def Foo(unittest.TestCase): @step(number=1) def test_foo(self): pass @step(number=2) def test_boo(self): pass From reviewing the built in plugins I had thought, I could simply override loadTestsFromTestCase and order the tests by the decorated 'step number'.: def loadTestsFromTestCase(self, cls): """ Return

How to run a single test or single TestCase with django-nose?

我与影子孤独终老i 提交于 2019-11-29 05:25:16
With Django's normal test runner, you can drill down to run tests in a specific app, a specific subclass of TestCase, or a specific test within a specific subclass of TestCase. E.g.: ./manage.py test myapp.MyTestCase.test_something However, django-nose doesn't appear to support anything beyond testing a specific app. How do I replicate the last two behaviors? Nose supports the following syntax (note : between test script name and test class name): ./manage.py test myapp.tests.test_script:MyTestCase.test_method The correct answer is ./manage.py test myapp/tests/test_script:MyTestCase.test

How do I capture a screenshot if my nosetests fail?

江枫思渺然 提交于 2019-11-29 02:26:58
I am running selenium webdriver tests with nosetests. I want to capture a screenshot whenever nosetests fail. How can I do it in the most effective way, either by using webdriver, python or nosetests features? My solution import sys, unittest from datetime import datetime class TestCase(unittest.TestCase): def setUp(self): some_code def test_case(self): blah-blah-blah def tearDown(self): if sys.exc_info()[0]: # Returns the info of exception being handled fail_url = self.driver.current_url print fail_url now = datetime.now().strftime('%Y-%m-%d_%H-%M-%S-%f') self.driver.get_screenshot_as_file('