Questions tagged [unittest2]
45 questions
3
votes
1 answer
How to get per-testcase scoping for dependency injected objects in Python?
I'm using python-inject, python 2.6 (with unittest2).
We have classes to test that use injection, and test-cases which also use the same values. We currently use inject.appscope, to "singletonize" the values. Otherwise they're instantiated per…

Macke
- 24,812
- 7
- 82
- 118
3
votes
2 answers
Is it possible to run doctests using unit2
I recently switched from nose to the new unittest2 package for my python unit testing needs. It does everything I want, except from the fact that I can't get its "discover" command to recognize the doctests in my code - I still have to use nose to…

c089
- 4,951
- 2
- 25
- 37
3
votes
0 answers
Python unittest: how to use setUpClass() and tearDownClass() with arguments
I would like to use python unittest setUpClass and tearDownClass methods with arguments. More specifically, here is what I am doing now:
import unittest2 as unittest
cache = VCache(arg1, arg2, arg3)
class Validation(unittest.TestCase):
''' Unit…

dr.haz
- 1,497
- 1
- 10
- 5
3
votes
4 answers
Django unittests - ImproperlyConfigured error
Im trying to write tests for my module. When i run:
python manage.py test my_module
Im getting message:
django.core.exceptions.ImproperlyConfigured: Please fill out the database NAME in the settings module before using the database.
I dont have…

marxin
- 3,692
- 3
- 31
- 44
2
votes
2 answers
python unittest2 - exposing test method name to setup method
I need to find the name of the test method about to be run from within the SetUp() method that unittest runs before each test. How can I do this without running every test method seperately?
Example:
class Testing(unittest2.TestCase):
def…

yuvalshu
- 73
- 4
2
votes
1 answer
Have a single test method return multiple test results
Before I get you all confused, let me clarify: I'm NOT asking about running a single test method with different arguments. All clear? Then let's go:
I have a test in Python (Django, but not relevant) that basically...
starts a http server,
starts…

Kos
- 70,399
- 25
- 169
- 233
2
votes
2 answers
Is there a way to add metadata in py files for grouping tests?
Lets say I have the following testcases in different files
TestOne.py {tags: One, Two}
TestTwo.py {tags: Two}
TestThree.py {tags: Three}
Each of which inherits from unittest.TestCase. Is there any ability in python to embed metadata information…

Thunderboltz
- 1,597
- 3
- 14
- 16
2
votes
3 answers
How to do an "early return" of an import under Nose?
I'm curating a large number of unit tests for a large Python project. We use nose to do our test discovery and execution. I have some test files that really shouldn't be run in certain conditions. For instance, maybe I have a test module that…

dbn
- 13,144
- 3
- 60
- 86
2
votes
3 answers
What is the most pythonic way to support unittest2 features across a range of Python versions?
I can think of two ways to ensure that I can use modern features from the unittest library across a wide range of Python versions:
try:
from unittest2 import TestCase
except ImportError:
from unittest import TestCase
or
import sys
if…

snth
- 5,194
- 4
- 39
- 48
2
votes
1 answer
python nose from a script, gathers test classes from files and then runs tests
How would I use nose from a python script to
gather python files from a directory
foreach file
run all test classes found using passed parameters
Here's an example, given files
/run.py
/tests/TestClassA.py
and within TestClassA.py is the code
…

JamesThomasMoon
- 6,169
- 7
- 37
- 63
1
vote
2 answers
Unit Testing a c# project which uses native code
I have three projects
1)unmanaged c++ containing full business logic
2)C++/CLI (Project name managed)
3)C# GUI
I have added the library file of unmanaged c++ in C++/CLI and then dll of C++/CLI in C# project.This this all is working fine and…

manu_dilip_shah
- 880
- 14
- 32
1
vote
1 answer
What's a good practice when unittesting views that perform calls to external services in django
We have this view that look something like this:
from fblib import Facebook
def foo(request):
fb = Facebook( settings.facebook )
data = fb.get_thingy()
return render_to_response( .. , data, .. )
What would be a good way of testing…

Kit Sunde
- 35,972
- 25
- 125
- 179
1
vote
2 answers
python unittest2 assertAlmostEqual with `places` works incorrectly
I am dealing with the following problem with unittest2:
assertAlmostEqual(69.88, 69.875, places=2) # returns True
but
assertAlmostEqual(1.28, 1.275, places=2) # returns False
I think problem is in the assertAlmostEqual method:
def…

ruscoder
- 13
- 2
1
vote
1 answer
No api proxy found for service "memcache" GAE unittest2
I'am trying to write tests to my app. I make a simple test case:
def test_put(self):
Result(
id="23738",
target_id="23738",
).put()
and after running, it raises an error:
AssertionError: No api proxy found for service…

mr_ivan777
- 401
- 1
- 10
- 17
1
vote
2 answers
Is it possible to mock the string module from Python?
For instance, if I have a call to the split method (i.e. some_string.split(":") )
Is is possible to mock this. I wanted to assert that the split function is called using assert_called_once_with

user1941192
- 43
- 1
- 7