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
155
votes
6 answers

How do I run a single test with Nose in Pylons

I have a Pylons 1.0 app with a bunch of tests in the test/functional directory. I'm getting weird test results and I want to just run a single test. The nose documentation says I should be able to pass in a test name at the command line but I get…
Ben
  • 10,931
  • 9
  • 38
  • 47
126
votes
13 answers

How to assert output with nosetest/unittest in python?

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 =…
Pedro Valencia
  • 1,277
  • 2
  • 9
  • 3
124
votes
9 answers

Python Nose Import Error

I can't seem to get the nose testing framework to recognize modules beneath my test script in the file structure. I've set up the simplest example that demonstrates the problem. I'll explain it below. Here's the the package file…
halfak
  • 1,716
  • 2
  • 13
  • 17
116
votes
10 answers

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

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…
jkp
  • 78,960
  • 28
  • 103
  • 104
112
votes
4 answers

Mocking two functions with patch for a unit test

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…
cnodell
  • 1,191
  • 2
  • 7
  • 8
102
votes
7 answers

How to set self.maxDiff in nose to get full diff output?

When using nose 1.2.1 with Python 3.3.0, I sometimes get an error message similar to the following one ====================================================================== FAIL:…
Loïc Séguin-C.
  • 1,806
  • 2
  • 13
  • 14
91
votes
4 answers

setting breakpoints with nosetests --pdb option

nosetests --pdb let's me halt upon error or failure, but this is too late for my needs. Stepping through code during execution helps me debug where the problem is. However, nosetests are helpful as they allow tests that rely on relative imports…
Devin
  • 2,113
  • 2
  • 22
  • 28
88
votes
1 answer

nose vs pytest - what are the (subjective) differences that should make me pick either?

I've started working on a rather big (multithreaded) Python project, with loads of (unit)tests. The most important problem there is that running the application requires a preset environment, which is implemented by a context manager. So far we made…
Jakob van Bethlehem
  • 1,066
  • 1
  • 7
  • 10
86
votes
7 answers

How to run unittest discover from "python setup.py test"?

I'm trying to figure out how to get python setup.py test to run the equivalent of python -m unittest discover. I don't want to use a run_tests.py script and I don't want to use any external test tools (like nose or py.test). It's OK if the…
cdwilson
  • 4,310
  • 4
  • 26
  • 32
79
votes
4 answers

How to change the message in a Python AssertionError?

I'm writing per the following, in which I try to produce a decent error message when comparing two multiline blocks of Unicode text. The interior method that does the comparison raises an assertion, but the default explanation is useless to me I…
Andres Jaan Tack
  • 22,566
  • 11
  • 59
  • 78
75
votes
10 answers

Scrapy Unit Testing

I'd like to implement some unit tests in a Scrapy (screen scraper/web crawler). Since a project is run through the "scrapy crawl" command I can run it through something like nose. Since scrapy is built on top of twisted can I use its unit testing…
ciferkey
  • 2,064
  • 3
  • 20
  • 28
74
votes
15 answers

Getting Python's unittest results in a tearDown() method

Is it possible to get the results of a test (i.e. whether all assertions have passed) in a tearDown() method? I'm running Selenium scripts, and I'd like to do some reporting from inside tearDown(), however I don't know if this is possible.
Joey Robert
  • 7,336
  • 7
  • 34
  • 31
72
votes
3 answers

Why python mock patch doesn't work?

I have two files spike.py class T1(object): def foo(self, afd): return "foo" def get_foo(self): return self.foo(1) def bar(): return "bar" test_spike.py: from unittest import TestCase import unittest from mock import…
LeoShi
  • 1,637
  • 2
  • 14
  • 24
66
votes
3 answers

Python imports for tests using nose - what is best practice for imports of modules above current package

This is a question which is asked frequently in different forms, and often obtains "lol you're not doing it properly" responses. Pretty sure that's because there's a common sense scenario people (including me) are trying to use as an implementation,…
leonigmig
  • 2,736
  • 3
  • 25
  • 21
64
votes
2 answers

How to Fix Python Nose: Coverage not available: unable to import coverage module

I can't seem to get code coverage with Nose to work, despite having the plugin installed. Any ideas on how to fix this? 12:15:25 ~/sandbox/ec$ nosetests --plugins Plugin xunit Plugin deprecated Plugin skip Plugin multiprocess Plugin…
doremi
  • 14,921
  • 30
  • 93
  • 148
1
2 3
69 70