Questions tagged [nose]

Nose is an alternate Python unittest discovery and running process. It is intended to mimic the behavior of py.test as much as is reasonably possible.

Nose is an alternate unittest discovery and running process. It is intended to mimic the behavior of py.test as much as is reasonably possible.

Resources

1036 questions
14
votes
1 answer

nose, unittest.TestCase and metaclass: auto-generated test_* methods not discovered

This is a follow-up question for unittest and metaclass: automatic test_* method generation: For this (fixed) unittest.TestCase layout: #!/usr/bin/env python import unittest class TestMaker(type): def __new__(cls, name, bases, attrs): …
Santa
  • 11,381
  • 8
  • 51
  • 64
14
votes
2 answers

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

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…
jwg
  • 5,547
  • 3
  • 43
  • 57
14
votes
2 answers

Where does the nose.collector look for tests?

I want to use nose.collector as a test suite for setuptools, as described here. My package's source lives in mypackage/src, and I have tests in mypackage/tests. I have a setup.py that looks like this: import setuptools setuptools.setup( …
limp_chimp
  • 13,475
  • 17
  • 66
  • 105
14
votes
2 answers

Nose doesn't find Django tests

I am trying to use Django-nose in my current project, but I can't figure out how to get nose to run my tests. So I started a simple Django 1.4.1 project to get to know nose. But not even on this simple test project I could get it running. Before I…
Jens
  • 20,533
  • 11
  • 60
  • 86
13
votes
1 answer

Python import fails on travisCI but not locally

I'm trying to integrate TravisCI into my workflow, and realized I had some dependencies because of my old directory structure (not having self-contained, virtualenv-able git repos). When I try to run nosetests locally, it runs the tests just fine;…
dwanderson
  • 2,775
  • 2
  • 25
  • 40
13
votes
2 answers

Run specific Django tests (with django-nose?)

I am having a very complicated tests.py file. Actually the tests classes and methods are generated at run time w/ type (to account for data listed in auxiliary files). I am doing things in the following fashion (see below for more code): klass =…
lajarre
  • 4,910
  • 6
  • 42
  • 69
13
votes
2 answers

Conditional skip TestCase decorator in nosetests

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…
ziima
  • 706
  • 4
  • 17
13
votes
5 answers

How to use cProfile with nosetest --with-profile?

nosetest --with-profile --profile-stats-file output The output can't read by runsnake, because nosetest uses hotshot, if I want to generate a file that can be read with runsnake, I need to convert it so: st =…
Virako
  • 650
  • 10
  • 18
12
votes
1 answer

Python Nose: Log tests results to a file with Multiprocess Plugin

Im trying to log my tests output to a file as well as running them concurrently. For this Im trying to use the multiprocess plugin and the xunit plugin. Im aware that they dont work together, xunit doesnt log anything because mutiprocess doesn't…
dgrandes
  • 1,187
  • 2
  • 14
  • 28
12
votes
2 answers

Passing options to nose in a Python test script

Rather than running my nose tests from the command line, I'm using a test runner that sets up a few things for all the tests, including a connection to a local test instance of MongoDB. The documentation for nose only seems to indicate how to pass…
Matt W
  • 6,078
  • 3
  • 32
  • 40
12
votes
2 answers

Python test fixture to run a single test?

I'm looking for something like ruby rspec's focus metadata or elixir's mix tags to run a single python test. Ruby RSpec Example: # $ rspec spec it 'runs a single test', :focus do expect(2).to eq(2) end Elixir ExUnit & Mix Example: # $ mix test…
daino3
  • 4,386
  • 37
  • 48
12
votes
3 answers

Detecting when code is run on Travis CI

I have a nose test that uses a pathname to a png file in the tests directory. One path works in local testing, one path works on Travis. How do I check when the code is run on Travis? Edit: Here is the actual code.
ArekBulski
  • 4,520
  • 4
  • 39
  • 61
12
votes
3 answers

Mock python function with multiple return values

I have a python function that returns multiples values. My function: def myExampleFunction(a,b) # here is my code return name, number1, number2 def FunctionIWantToTest(self): # here is my code myName, myNumber1, myNumber2 =…
myg
  • 185
  • 2
  • 2
  • 8
12
votes
1 answer

Timeout on tests with nosetests

I'm setting up my nosetests environment but can't seem to get the timeout to work properly. I would like to have an x second (say 2) timeout on each test discovered by nose. I tried the following: nosetests --processes=-1…
JustMe
  • 237
  • 4
  • 7
12
votes
3 answers

How can I mock sqlite3.Cursor

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…
Kristjan Oddsson
  • 343
  • 3
  • 18