Python's framework for unit testing.
0
votes
2answers
14 views
Is it possible to patch a class instance with an existing Singleton instance?
I have a class representing our DB layer which is being instantiated internally in some classes (I cannot pass it as an outside parameter)
For example:
class MyClass(object):
def __init__(self):
...
0
votes
0answers
6 views
Web2py - Unittest GET request
All,
I am trying to unittest a GET request, I have had no problem testing all my other functions which were POST requests.
I have a simple function, that takes two vars; a file name and a path and ...
0
votes
0answers
18 views
Python mocking shutils always passes
I have a module with many utility functions, most of which exec system calls. One example is a function that copies a file to a new directory and returns the path. I am writing unit tests for my ...
1
vote
2answers
28 views
Unittesting Pyramid/Cornice resource with query string in a URL
I have Pyramid/cornice resource, that requires a ?query=keyword in end of the url. But I don't know how to add this in a pyramid's dummyRequest object. Code works perfectly on browser and I will get ...
0
votes
0answers
17 views
Python - Wrong directory when execute from terminal
If I run from the IDE the dir path is ok, but when I execute from termianl, I am geeting a exception:
Code:
def __init__(self):
dir = os.path.abspath(os.path.join(__file__, os.pardir))
...
0
votes
0answers
4 views
Which are some suggestions for HTML Test Report Generator using Python
I need some suggestions from you brilliant people on generating HTML reports from python unittests,using Selenium. Something on the line of HTMLTestRunner.
It is a good program,and reports are also ...
1
vote
2answers
33 views
How can I test that a method on an imported module is called during object construction
I'm working on a Reddit bot to learn TDD in python.
I have a module with a class that is something like this:
from praw import Reddit
class Bot():
def __init__(self):
self.reddit = ...
1
vote
1answer
34 views
Issue with running test from terminal
I am working with Python 2.7.9 in PyCharm
This is my project structure:
/JUAN
/framework
/config
/page_objects
/locators
/tests
/log_in
...
2
votes
1answer
31 views
Is it possible to simulate the unavailability of modules in Python tests?
I've written a Python program that makes use of the resource module on Unix systems to do some timing operations, but falls back to using the time module on Windows (since the resource module is ...
0
votes
1answer
14 views
Mock class used in isinstance checks which has dynamic attributes
Some classes define their attributes (aka fields) at the class level (outside __init__ or any other function). Some classes define them inside their __init__ function or even from other functions. ...
0
votes
0answers
22 views
Thread server broken pipe error
I have ThreadedSimpleServer. Now I want to test it with unittest. In test.py file I have class Test(unittest.TestCase).
if __name__ == '__main__':
# create service
service = Service()
# run service ...
1
vote
1answer
23 views
Dependent unit tests
I have a program that gives an output based on parameters object as input and information stored in a database.
I am trying to test this program with 2 test cases, the first of which gives no ...
1
vote
1answer
41 views
How to send requests with JSONs in unit tests
I have code within a Flask application that uses JSONs in the request, and I can get the JSON object like so:
Request = request.get_json()
This has been working fine, however I am trying to create ...
0
votes
1answer
26 views
how to post an image file in the django rest framework
i am doing unit tests on my rest framework API, my model:
class attach():
attachment = models.ImageField
name = models.CharField
then i attempt to post to is via the API i defined(standard ...
0
votes
0answers
17 views
Limited streaming via a mock
I have a project in which I am accessing a server that returns an object stream. Concurrently I am working on enhancing my TDD-fu. I'm not very familiar with mocking, as with Python's httpretty ...
2
votes
1answer
70 views
How do I enter pdb debugger when the datastore is started in setUp(unittest.TestCase)?
I'm confused. It would seem that Client entity should exist because I have 2 locations for it to be created:
I create the requested Entity in the the setUp() of the unittest.TestCase.
I also ...
1
vote
1answer
50 views
How to unittest GPIO output value of raspberry pi in Python
I am making Raspberry Pi program by using python.
I want to write unittest of my python code.
How can I get output status of GPIO?
test target class is bellow. I want to check outputs after calling ...
0
votes
0answers
20 views
Passing arguments to python unittests tests functions
C#'s NUnit has an ability to run the same test several times with different arguments:
[TestCase(12,2,6)]
[TestCase(12,4,3)]
public void DivideTest(int n, int d, int q) {
Assert.AreEqual( q, n / d ...
0
votes
0answers
10 views
unitTest continuous assertTrue [duplicate]
I am new to unittest. I was wondering what can I use to run a lot of assertTrue and report the count of how many tests pass and also where the failures occurred.
For instance, I have
a = [False, ...
0
votes
1answer
37 views
AttributeError: object has no attribute 'runTest'
I'm am new to unittest and I am not sure why I am getting this error:
runTest (__main__.TestTimeInterval)
No test ... Traceback (most recent call last):
File ...
0
votes
1answer
33 views
Can't import module in virtualenv
I'm trying to learn flask. I have created a virtualenv and am using the hello.py example file as in here.
For reference, the contents of hello.py is as follows:
from flask import Flask
app = ...
0
votes
1answer
28 views
Python Mock with `from X import y`
I am trying to use Python's mock library in my unit testing but I am seeing inconsistent results depending on how I import the target that I am trying to patch. I would expect that both of these print ...
0
votes
2answers
52 views
python unittest count tests
Is it possible with unittest to have an option tou count the number of total test number of skipped tests and number of run. And after the run the number of test failed (I know that it can be seen in ...
0
votes
1answer
28 views
Unittest for context-manager fails with AttributeError: __exit__
I'm trying to understand the correct way to unit test code with context-manager (with statement).
Here is my sample code:
class resources():
def __init__(self):
self.data = 'at-init'
...
1
vote
0answers
27 views
Mocking function of Django default method parameter with unittest-mock
I am trying to mock the infamous datetime.now() function so that I have a frozen date easy to test in my unit test. I usually use unittest-mock package to do so, patching the datetime object of the ...
2
votes
0answers
45 views
I'm lost with trying to write tests to my Flask application
So I've tried writing some tests for my Flask application for a couple of days but I can't get it to run. The tests pass but it gets stuck on PASSED.
I've cloned cookiecutter-flask ...
1
vote
1answer
25 views
Python Define Unit Test Classes Together with Code
I am rapid prototyping so for now I would like to write unit tests together with the code I am testing - rather than putting the tests in a separate file. However, I would only like to build the test ...
0
votes
1answer
51 views
How to use Python mocking in a unit test
Most advice on Python mocking is couched in short snippets outside of the unit test framework. This one works find, I'm trying to follow this advice, but it's not successful as soon as I embed it in a ...
-1
votes
1answer
88 views
unittest vs pytest vs nose [closed]
I'm new in python testing and am having some diffiulties choosing between
unittest, pytest and nose nose.
I'm bulding a test lib that requires : installing a package changing the conf restarting ...
0
votes
1answer
37 views
Why does Selenium with PhantomJS return the wrong page_source?
I'm using selenium from Python with the Phantomjs webdriver. I'm running both Selenium and my server locally on my laptop. When I run my test:
class TestNotLoggedIn(unittest.TestCase):
def ...
-1
votes
1answer
33 views
web2py - Unit testing @auth.requires_login()
All,
I have created a unit test for my web2py app.
I mainly followed this slice: http://www.web2pyslices.com/slice/show/1465/unittesting-doctesting-and-userinterface-testing
I can register and ...
0
votes
1answer
17 views
Test part of complex structure with unittest and mocks
What will be the best way to test following:
We have a large complex class that we'll call ValueSetter which accepts string, gets some data from it and sets this data to several variables like
...
0
votes
1answer
27 views
Limitations of assertEqual
The docs for assertEqual in Python unittest say
assertEqual(first, second, msg=None)
Test that first and second are equal. If the values do not compare equal, the test will fail
If my ...
0
votes
0answers
5 views
How to add unittests configuration to Pychar 4
I have functional test written for my Flask application using unittests engine. It has following structure:
+-> tests
|
+-> run_webdriver.py #run test suites gathered from ...
-4
votes
1answer
68 views
how to do Python unittest for while loop?
when I write unit testcase, I don't know how to design while loop's testcase.
could someone give me a guid to write a unit testcase for below while loop code snippet?
many thank.
def judge(arg):
...
0
votes
1answer
19 views
Unittests not run with python -m unittest command
I have such structure
app/
__init__.py
phonebook.py
test_phonebook.py
Being in app directory I can run tests in terminal with python test_phonebook.py
But why tests do not run when I ...
0
votes
0answers
9 views
Flask TestCase can not found urls after refactoring
Before I had all my code(models, views) in single file run.py and everything worked
Now I've created such structure
And in browser my app works correctly, but when I run tests, for each request
...
0
votes
1answer
52 views
TDD with python, unexpected unittest error
This is my code;
from selenium import webdriver
import unittest
class NewVisitorTest(unittest.TestCase):
def setup(self):
self.browser = webdriver.Firefox()
...
-1
votes
1answer
67 views
How to use a pandas data frame in a unit test
I am developing a set of python scripts to pre-process a dataset then produce a series of machine learning models using scikit-learn. I would like to develop a set of unittests to check the data ...
3
votes
2answers
45 views
How can I write unit tests against code that uses matplotlib?
I'm working on a python (2.7) program that produce a lot of different matplotlib figure (the data are not random). I'm willing to implement some test (using unittest) to be sure that the generated ...
0
votes
0answers
14 views
How to pass a function I want to check as a parameter to unittest.TestCase in Python 3.x
For example, I have functions that are working with strings. And I would like to create an unittest, which is checking the functions. Sometimes, tests are identical, so I was thinking for creating ...
0
votes
1answer
28 views
python unittest where does the “X tests run” number come from?
import unittest
class Tests(unittest.TestCase):
def test_one(self):
a = 1
self.assertEqual(a,1)
def test_two(self):
b = 2
c = 3
d = 4
...
0
votes
2answers
49 views
Unittest failed with sys.exit
I'm trying to run my tests with unittest. Here is my structure :
projectname/
projectname/
foo.py
bar.py
tests/
test_foo.py
test_bar.py
I run it with :
cd ...
1
vote
1answer
41 views
Python HTMLTestRunner test report contains only partial test case names
I'm trying to setup a unit test with reports generated by HTMLTestRunner. The tests are running fine but the generated report doesn't contain full test case names, instead only the last part of the ...
1
vote
3answers
71 views
Python: how can I override a complicated function during unittest?
I am using Python's unittest module to test a script I am writing.
The script contains a loop like this:
// my_script.py
def my_loopy_function():
aggregate_value = 0
for x in range(10):
...
1
vote
1answer
80 views
assertIsInstance() against multiple class names
I have a function which should set an object attribute to a PIL Image instance:
from PIL import Image
class SimpleExample:
def __init__(self):
self.img = self.load_image()
def ...
3
votes
1answer
47 views
test initialization of object and use it [closed]
I have an class and I want to test it with the built in unittest module. In particular I want to test if I can create intances without throwing errors and if I can use them.
The problem is that the ...
1
vote
1answer
33 views
assert that an operation raises a Stopiteration
I have a generator that I want to confirm has ended (at a certain point in the program. I am using unittest in python 2.7
# it is a generator whould have only one item
item = it.next()
# any further ...
0
votes
1answer
40 views
unittest: better alternative to assertIn
Suppose I have a huge list as output that I want to test. I create a list with some random elements that I feel should be in my output list. This is what I come up with after reading the ...
1
vote
1answer
44 views
setuptools: Run tests on build dir instead of original dir
I'm currently trying to make a module written for Python2 compatible with Python3.2.
I started by making sure that all code can be automatically converted with 2to3 and added into setup.py:
use_2to3 ...