nose

django doctests not being run

流过昼夜 提交于 2019-12-05 12:44:25
I'm having a problem running django doctests with django-nose. Unit tests added to a /tests directory are running fine, but doctests are not. I am trying to run doctests on my "season" module: python manage.py test season and get this output: nosetests --verbosity 1 season --with-doctest Creating test database for alias 'default'... ---------------------------------------------------------------------- Ran 0 tests in 0.001s OK Destroying test database for alias 'default'... I'm just trying a basic doctest to try to get this to work, e.g.: """ >>> 1+1 == 2 True """ This is in my models.py. I've

Run nosetests with warnings as errors?

最后都变了- 提交于 2019-12-05 11:23:06
问题 When running nosetests from the command line, how do you specify that 'non-ignored' warnings should be treated as errors? By default, warnings are printed, but not counted as failures: [snip]/service/accounts/database.py:151: SADeprecationWarning: Use session.add() self.session.save(state) [snip]/service/accounts/database.py:97: SADeprecationWarning: Use session.add() self.session.save(user) ............ ---------------------------------------------------------------------- Ran 12 tests in 0

How can I mock sqlite3.Cursor

人走茶凉 提交于 2019-12-05 07:58:26
I've been pulling my hair out trying to figure out how to mock the sqlite3.Cursor class specifically the fetchall method. Consider the following code sample import sqlite3 from mock import Mock, patch from nose.tools import assert_false class Foo: def check_name(name): conn = sqlite3.connect('temp.db') c = conn.cursor() c.execute('SELECT * FROM foo where name = ?', name) if len(c.fetchall()) > 0: return True return False @patch('sqlite3.Cursor.fetchall', Mock(return_value=['John', 'Bob'])) def test_foo(): foo = Foo() assert_false(foo.check_name('Cane')) Running nosetests results in no fun

Getting tests to parallelize using nose in python

你。 提交于 2019-12-05 06:28:00
I have a directory with lots of .py files (say test_1.py, test_2.py and so on) Each one of them is written properly to be used with nose. So when I run nosetests script, it finds all the tests in all the .py files and executes them. I now want to parallelize them so that all the tests in all .py files are treated as being parallelizable and delegated to worker processes. It seems that by default, doing : nosetests --processes=2 introduces no parallelism at all and all tests across all .py files still run in just one process I tried putting a _multiprocess_can_split_ = True in each of the .py

Handling Exceptions in Python Behave Testing framework

依然范特西╮ 提交于 2019-12-05 03:45:40
I've been thinking about switching from nose to behave for testing (mocha/chai etc have spoiled me). So far so good, but I can't seem to figure out any way of testing for exceptions besides: @then("It throws a KeyError exception") def step_impl(context): try: konfigure.load_env_mapping("baz", context.configs) except KeyError, e: assert (e.message == "No baz configuration found") With nose I can annotate a test with @raises(KeyError) I can't find anything like this in behave (not in the source, not in the examples, not here). It sure would be grand to be able to specify exceptions that might be

Conditional skip TestCase decorator in nosetests

我是研究僧i 提交于 2019-12-05 01:21:06
Is there a way to skip whole TestCase based on custom condition using nosetests? I mean something in unittest.skip* style. I tried import unittest @unittest.skip("No reason") class TestFoo(object): def test_foo(self): assert False I found out this works using python <= 2.7.3 (apparently by accident), but in python 2.7.6 not. Is there a nosetests way to do this, or I have to create my own decorator? Notes: We tried all combinations of python 2.7.3, 2.7.6 and nosetests 1.1.2, 1.3.0. If the class is inherited from unittest.TestCase it works, but that is not what I need. It seems to work when

Pycharm - no tests were found?

烈酒焚心 提交于 2019-12-05 00:06:20
I've been getting a No tests were found error in Pycharm and I can't figure out why I'm getting it... this is what I have for my point_test.py : import unittest import sys import os sys.path.insert(0, os.path.abspath('..')) from ..point import Point class TestPoint(unittest.TestCase): def setUp(self): pass def xyCheck(self,x,y): point = Point(x,y) self.assertEqual(x,point.x) self.assertEqual(y,point.y) and this point.py , what I'm trying to test: import unittest from .utils import check_coincident, shift_point class Point(object): def __init__(self,x,y,mark={}): self.x = x self.y = y self.mark

How do I use PyMock and Nose with Django models?

两盒软妹~` 提交于 2019-12-04 19:11:13
I'm trying to do TDD with PyMock, but I keep getting error when I use Nose and execute core.py from command line: "ERROR: Failure: ImportError (Settings cannot be imported, because environment variable DJA NGO_SETTINGS_MODULE is undefined.)" If I remove "from cms.models import Entry" from the unit test module I created, everything works fine, but I need to mock functionality in django module cms.models.Entry that I created. What am I doing wrong? Can this be done? You do need DJANGO_SETTINGS_MODULE defined in order to run core.py -- why don't you just export DJANGO_SETTINGS_MODULE=whatever in

Make nose test runner show logging even if tests pass

依然范特西╮ 提交于 2019-12-04 15:28:42
问题 I am using nosetests test.py to run unit tests: import unittest import logging class Test(unittest.TestCase): def test_pass(self): logging.getLogger('do_not_want').info('HIDE THIS') logging.getLogger('test').info('TEST PASS') self.assertEqual(True, True) def test_fail(self): logging.getLogger('do_not_want').info('HIDE THIS') logging.getLogger('test').info('TEST FAIL') self.assertEqual(True, False) When test fails, it prints out all logging info. I can use --logging-filter to filer out only

How to achieve TestNG like feature in Python Selenium or add multiple unit test in one test suite?

安稳与你 提交于 2019-12-04 09:41:31
问题 Suppose I have this two nosetest ExampleTest1.py and ExampleTest2.py ExampleTest1.py class ExampleTest1(TestBase): """ """ def testExampleTest1(self): ----- ----- if __name__ == "__main__": import nose nose.run() --------------- ExampleTest2.py class ExampleTest2(TestBase): """ """ def testExampleTest2(self): ----- ----- if __name__ == "__main__": import nose nose.run() Now I want to run such hundreds of test files from a single suite. I am looking something like TestNG feature like testng