Tagged Questions
0
votes
0answers
4 views
Why does flask-testing spawn two test instances?
I want to use the LiveServerTestCase class which is provided by flask-testing to test my flask application in combination with Selenium.
I tried implementing the tests the way described in the ...
0
votes
0answers
16 views
How should I test the code with unittest and doctest?
I found one thing I can't solve it.. so please guys help. I've got two simple code examples in python. First reads numbers from file and returns a list of integer files. The second example just ...
0
votes
1answer
12 views
Running unit test of a module that imports another module in parent directory failed
The project structure is as follows:
/root
- /crawler
- /basic
- agent.py
- settings.py
- main.py
- /tests
- /basic
- test_agent.py
- test_main.py
main.py imports agent.py, and agent.py ...
0
votes
0answers
15 views
Concatenating files in a mockable/testable way
I have a use case where I have a bunch of files which I need to concatenate sequentially, deleting each file after it's been concatenated to the output. The code looks something like this:
def ...
1
vote
1answer
17 views
Django test client does not log in
I am attempting to log in the test client using its built in login function. I am trying to unit test views and need to log in to test some of them. I have been trying to do this for too long and need ...
0
votes
1answer
21 views
Python mock: mocking base class for inheritance
I am testing a class that inherits from another one very complex, with DB connection methods and a mess of dependences. I would like to mock its base class so that I can nicely play with the method ...
1
vote
1answer
16 views
How to test that matplotlib's show() shows a figure without actually showing it?
I have code where I show a figure, for example
import matplotlib.pyplot
pyplot.plot([1,2,3],[1,2,3])
pyplot.show()
How can I test that the pyplot.show() shows a figure without actually showing it? ...
2
votes
1answer
24 views
How to mock a decorated function
For testing reasons, I need to be able to mock the inner/original function of a decorated one which is used somewhere else:
In mydecorator.py:
def my_decorator(f):
def wrapped_f():
print ...
1
vote
1answer
14 views
How to check that all functions have a test case?
Is there a standard method to check if all functions of all files that are included in a test have a testcase? So if I have script_1.py, script_2.py and script_3.py with corresponding ...
1
vote
1answer
14 views
How to mock xml data excange for writing unittests in python
I am writing unit tests for functions in python which get and set xml data from/to the hardware's firmware. How can i mock such things. I am using python and nose
2
votes
1answer
59 views
how to sort class on datetime, sort collections.deque
I could really use some help in how to implement the getitem, iter methods or generator functions to sort a class and class container I have created.
I created a Report class that has send_time ...
0
votes
0answers
36 views
Python Unitttest for twitter bot
I working on simple twitter bot on Python. Every day my bot is unfollowing people that do not follow me. How can I write unit tests for methods follow and unfollow,that doesn't change real account's ...
1
vote
1answer
21 views
Inheriting from unittest.TestCase for non-test functionality
I want to write a class to check sets using exactly the behavior that unittest.TestCase.assertEqual exhibits for testing set equality. It automatically prints a nice message saying which elements are ...
1
vote
1answer
18 views
Class mocking in Django tests
I'm using mock 1.0.1 (http://www.voidspace.org.uk/python/mock/) to mock objects in my tests, and I'm able to mock dates using this approach:
def dateStub():
return ...
0
votes
0answers
5 views
Request comes as a list for Spyne NullServer service method
I use NullServer to test my Spyne app and to define methods request signature I follow bare body style. When I run it as a wsgi server it works fine, but when I use NullServer request comes as a list ...
0
votes
0answers
10 views
Testing Celery task instances
I have a setup like this:
class AbstractProcessTask(Task):
abstract = True
def helper_method(self, param1):
return param1.lower()
@celery.task
class ...
0
votes
0answers
28 views
Mocking Django ImageField Storage in a Unit Test
I have a custom django image field that overrides the default dictionary to change the storage to upload to S3. I'm trying to mock (i.e. set it back to FileSystemStorage) so that my tests don't hit ...
2
votes
0answers
18 views
Can nose-parametrized be used with proboscis?
Is it possible to combine
https://pypi.python.org/pypi/nose-parameterized
with
https://pypi.python.org/pypi/proboscis
? Or is there any other way to achieve such functionality with proboscis? ...
0
votes
2answers
36 views
Run python unit test with python 2.7 and 3.x
I run my python unit tests by executing my test file through the shell and invoking
if __name__ == '__main__':
unittest.main()
at the end of the test file.
I have to support python 2.7 and ...
1
vote
0answers
23 views
How to unit test/mock requests.get(url) & its response
I am having trouble unit testing a function that uses Kenneth Reitz's requests library:
The following function is to be unit tested:
def getPage(url):
r = requests.get(url)
...
0
votes
1answer
20 views
python nose coverage plugin too thorough (forced pylib option)
I am using nose 1.3.0 and coverage 3.7.
Running on a command line
coverage run test_myfile.py
coverage report
produces a report that limits itself to the functions in myfile.py:
Name ...
2
votes
1answer
52 views
How to mock a function inside of another function?
I have been trying to mock this function call in another function with no success. How do I successfully mock this?
from mock import patch
from path.to.a import function_a
...
2
votes
2answers
27 views
python module variable not mutable as a function_default
I need to unit-test a python module by changing a default in the head of the application module called process.py. The declared default is a fixed int. I could change it to use something else from ...
0
votes
1answer
31 views
python unittest import classes sub directories
I have a project structured like this:
|tools/
|-- test/
| |-- __init__.py
| |-- test_class1.py
| |-- test_class2.py
|
|-- tools/
|-- __init__.py
| |-- class1.py
| |-- class2.py
|
|-- ...
1
vote
1answer
60 views
Python testing a class
Using a simple class with a lot work for initialization:
class MyClass():
def __init__(self, attr1, attr2):
self._init_method1(attr1)
self._init_method2(attr2)
...
0
votes
1answer
17 views
How to use python Mock side_effect to act as a Class method in unit test
I am testing a custom API in python that makes http requests, but I don't want to make a request to the real external system every time I run the unit tests. I am using python's mock library with a ...
2
votes
1answer
56 views
How do I mock the filesystem in python unit tests
Is there a standard way (without installing third party libraries) to do cross platform filesystem mocking in python? If I have to go with a third party library, which library is the standard?
It ...
1
vote
1answer
16 views
Python unittest/test fixture testing if module is loaded
I'm using another SO recommendation for importing simplejson, which reads as follows:
try:
import simplejson as json
except ImportError:
import json
However, in writing my unittest to see ...
1
vote
1answer
36 views
How can I mock a class method of a celery Task
Using python 2.7, celery 3.0.24 and mock 1.0.1. I have this:
class FancyTask(celery.Task):
@classmethod
def helper_method1(cls, name):
"""do some remote request depending on name"""
...
2
votes
4answers
60 views
Assert equality of floating point values to a significant figure tolerance
I am trying to write a unittest to check the output of an engineering analysis. I have theoretical values which i want to check against the analysis to a certain number of significant figures. so, for ...
0
votes
0answers
35 views
Running Django test with setup.py test and tox
I built a Django app and made a package out of it with setuptools. Now, I would like to do the following things:
I would like to run all tests with python setup.py test. But when I issue this ...
0
votes
1answer
24 views
Neo4j ImpermanentDatabase in python unittests
I am trying to create unit tests for a python project that will interface with a Neo4j Graph database.
Currently, I am implementing the embedded graph database, but will likely migrate to a REST ...
0
votes
1answer
37 views
How to test data with authorized user?
im new in django testing and i need your help. I have method that returns some data and depends on the user's authorization. I use Django 1.5 and py.test. Example:
def get_data(request, ...
0
votes
1answer
33 views
Mocking not working with pytest and flexmock
I'm trying to use pytest fixtures to mock calls to open() and then reset it on test teardown, but for some reason the mock is not applied in the test function.
Here's a sample of what I have:
# ...
0
votes
0answers
51 views
ImportError: No module named tests_utils. When I use ./manage.py test
When I try to run my django tests using 'manage.py test app_name' I get an error.
File "path/site/ENV/lib/python2.7/site-packages/django/test/utils.py", line 140, in get_runner
test_module = ...
1
vote
1answer
17 views
Passing a Mock() into blinker signal.connect() raises “AttributeError: __name__”
I am in the process of refactoring existing code to use the blinker library instead of passing around callback functions. I have a large set of existing tests which make use of mock to check that the ...
0
votes
1answer
23 views
django/python view testing(data from ModelForm)
I have a django view which adds the data from request to database(i've done that with using ModelForms). I have this ModelForms class:
class AddForm(forms.ModelForm):
class Meta:
model = Product
...
0
votes
1answer
32 views
How to mock databases access while testing urls with Django
I want to test some django application urls. However, the associated views are linked to the database. What I'd like to do is mocking these aspects of the view method, but I have no idea how.
Let's ...
4
votes
2answers
69 views
How to send username:password to unittest's app.get() request?
This is part of my unit test in Flask-RESTful.
self.app = application.app.test_client()
rv = self.app.get('api/v1.0/{0}'.format(ios_sync_timestamp))
eq_(rv.status_code,200)
Within the command line ...
0
votes
1answer
32 views
Django/python testing django form
I'm testing my project, and I need to test django form, but I don't know how to do it, here's the code
if request.method == 'POST': # If the form has been submitted...
name_add = ...
0
votes
2answers
20 views
Python/Django tests running only one test at a time
I have a unittest for my view
class TestFromAllAdd(TestCase):
fixtures = ['staging_accounts_user.json',
'staging_main_category.json',
'staging_main_dashboard.json',
...
0
votes
0answers
18 views
Difference in results between unit-tests launched with django and unit-tests launched with Eclipse
I have a unit test class that have different results when launched with django or with Eclipse.
When I launch them with the django framework, it pass with no problem :
test_make_in_active_exception ...
0
votes
3answers
45 views
How can unit test make changes to code quicker?
The following point (in bold) is mentioned in this famous Stackoverflow question:
Unit Tests allows you to make big changes to code quickly. You know it works now because you've run the tests, ...
0
votes
0answers
28 views
Starting unittests from python console
Is there a way to start unittests from the python console?
What I have in mind is something like the following (assuming mypackage is properly installed and found in the pythonpath and I started ...
-2
votes
0answers
28 views
Changing python params file at run time
In my program I have a param.py file with parameters, i.e:
DO_THIS = True
DO_THAT = False
I access this parameters throughout my program with:
from param import DO_THIS, DO_THAT
My problem is ...
1
vote
1answer
44 views
Python, Django Unit testing. RequestFactory test doesnt work
I have this view that I want to test
def change_item(request):
name_change = request.POST.get('name_change')
cost_change = request.POST.get('cost_change')
category_change = ...
0
votes
2answers
1k views
Monkey patch a function in a module for unit testing
I have the following method in a module that calls another method imported from another module:
def imported_function():
do_unnecessary_things_for_unittest()
The actual method that needs to be ...
11
votes
3answers
6k views
mocking functions using python mock
I am trying to Mock a function (that returns some external content) using the python mock module (http://www.voidspace.org.uk/python/mock/index.html).
I'm having some trouble mocking functions that ...
94
votes
9answers
32k views
Writing unit tests in Python: How do I start?
I completed my first proper project in Python and now my task is to write tests for it.
Since this is the first time I did a project, this is the first time I would be writing tests for it.
The ...
13
votes
4answers
3k views
Google App Engine Python Unit Tests
I'd like to write some Python unit tests for my Google App Engine. How can I set that up? Does someone happen to have some sample code which shows how to write a simple test?