Questions tagged [unittest2]
45 questions
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
63
votes
3 answers
`python -m unittest discover` does not discover tests
Python's unittest discover does not find my tests!
I have been using nose to discover my unit tests and it is working fine. From the top level of my project, if I run nosetests I get:
Ran 31 tests in 0.390s
Now that Python 2.7 unittest has…

blokeley
- 6,726
- 9
- 53
- 75
33
votes
1 answer
Why are unittest2 methods camelCase if names_with_underscores are preferred?
Here's the section of PEP8 that describes how function names should be:
Function names should be lowercase, with words separated by
underscores as necessary to improve readability.
mixedCase is allowed only in contexts where that's already the…

the_drow
- 18,571
- 25
- 126
- 193
21
votes
3 answers
How do I handle multiple asserts within a single Python unittest?
This is a problem that came up when performing a single test that had multiple independent failure modes, due to having multiple output streams. I also wanted to show the results of asserting the data on all those modes, regardless of which failed…

Eric Anderton
- 211
- 1
- 2
- 4
21
votes
4 answers
How can you get unittest2 and coverage.py working together?
How can you get unittest2 and coverage.py working together?
In theory something like
coverage run unit2 discover
should work, but it currently just errors out.
If you are a nose user that will be the equivalent of nosetests --with-coverage.

Jorge Vargas
- 6,712
- 7
- 32
- 29
18
votes
3 answers
How to run specific test in Nose2
In previous version of Nose testing framework, there were several ways to specify only a subset of all tests:
nosetests test.module
nosetests another.test:TestCase.test_method
nosetests a.test:TestCase
nosetests…

Tomáš Ehrlich
- 6,546
- 3
- 25
- 31
11
votes
2 answers
Order of tests in python unittest
I was looking at similar questions and I couldn't find an answer to my problem.
I wrote Tests in a python class that derives from unittest.TestCase
class TestEffortFormula(unittest.TestCase)
I need to give an order to the tests (please, do not tell…

slashms
- 928
- 9
- 26
11
votes
2 answers
How to assert that a method is decorated with python unittest?
I have a decorator and I want to assert that certain methods in my code are decorated with it.
import functools
def decorator(func):
def _check_something(*args, **kwargs):
# some logic in here
return func(*args, **kwargs)
…

Evgeny
- 6,533
- 5
- 58
- 64
8
votes
1 answer
Solving the confusion generated by too many ways to run unittest in python
I am trying to implement a full and clean way of testing python packages, one that would suit the folowing requirements:
execute tests on clean machines without setting them up (virtualenv)
gather results from multiple platforms
gather results from…

sorin
- 161,544
- 178
- 535
- 806
6
votes
2 answers
ImportError: No module named test_data, but test_data.py in same directory as test.py under PyCharm using virtualenv
In test.py, I am trying to import test_data:
import unittest2
import re
from test_data import receipt1_example
test_data.py is in the same directory as test.py. I get the following error:
/Users/ahammond/.virtualenvs/ric2.6/bin/python2.6
…

Andrew
- 1,027
- 1
- 11
- 17
5
votes
2 answers
Unit testing objects in Python - Object is not over written in setup
I'm unit testing classes in Python using unittest. As I understand it, unittest calls the setUp function before each test so that the state of the unit test objects are the same and the order the test are executed wouldn't matter.
Now I have this…

skytreader
- 11,467
- 7
- 43
- 61
4
votes
1 answer
Running python unit test over LSF
I need to parallelize my python unit-tests which I wrote using the default unittest module.
I'm trying to decide between two approaches:
keep using unittest but use a custom 'multiprocess' runner which can spawn a test using Platform LSF (remote…

sherve
- 300
- 2
- 10
4
votes
1 answer
How to use unittest2 in python setup.py test
How can I force python setup.py test to use the unittest2 package for testing instead of the built-in unittest package?

argentpepper
- 4,202
- 3
- 33
- 45
3
votes
0 answers
Django unit tests spews database error - cannot commit transaction - SQL statements in progress
I'm using unittest2 together with manage.py test, and before it even seems to run any tests, it spews a horrid database error, as below. I'm in my development environment (actually on a dreamhost server for a variety of reasons), using sqlite as my…

Marcin
- 48,559
- 18
- 128
- 201
3
votes
1 answer
Python Unittest2 - avoid including a TestCase in discover()
I'm using unittest2 on Python2.5 to discover tests with unittest.TestLoader.discover, like this:
suite = unittest2.loader.TestLoader().discover(test_path)
unittest2.TextTestRunner(verbosity=2,
resultclass=ColorTestResult).run(suite)
for…

Brian M. Hunt
- 81,008
- 74
- 230
- 343