I am currently trying to write some unit tests for my Flask application. In many of my view functions (such as my login), I redirect to a new page. So for example:
@user.route('/login', methods=['GET', 'POST'])
def login():
....
return…
I'm trying to use py.test's fixtures with my unit tests, in conjunction with unittest. I've put several fixtures in a conftest.py file at the top level of the project (as described here), decorated them with @pytest.fixture, and put their names as…
I realize unittest.mock objects now have an assert_not_called method available, but what I'm looking for is an assert_not_called_with. Is there anything like that? I looked on Google and didn't see anything, and when I tried just using…
Im trying to patch multiple methods in a class. Here is my simplified set up
Hook.py is defined as
class Hook():
def get_key(self):
return "Key"
def get_value(self):
return "Value"
HookTransfer.py defined as
from Hook…
I am trying to use PyCharm for unit testing (with unittest), and am able to make it work: the test runner nicely shows the list of test cases and nested test functions.
However, once the tests have been discovered, I cannot find any way to (re)run a…
I have project with the following directory structure:
.
├── requirements.txt
├── main.py
├── tests
├── unit
│ └── test_thing1.py
│ └── test_thing2.py
└── integration
└── test_integration_thing1.py
└──…
Hi How can i generate test method dynamically for a list or for number of files.
Say I have file1,file2 and filen with input value in json. Now I need to run the same test for multiple values like below,
class Test_File(unittest.TestCase):
def…
I have a problem with PyCharm 3.0.1 I can't run basic unittests.
Here is my code :
import unittest from MysqlServer import MysqlServer
class MysqlServerTest(unittest.TestCase):
def setUp(self):
self.mysqlServer = MysqlServer("ip",…
In my UnitTest directory, I have two files, mymath.py and test_mymath.py.
mymath.py file:
def add(a, b):
return a + b
def subtract(a, b):
return a - b
def multiply(a, b):
return a * b
def divide(numerator, denominator):
return…
I currently work on some code that uses unittest2 module. I suspect this code was meant for the python2. Can one use python3 unittest as a drop in replacement for unittest2? What is the difference between the two?
How to capture the stdout/stderr of a unittest in a variable? I need to capture the entire output output of the following unit test and send it to SQS. I have tried this:
import unittest, io
from contextlib import redirect_stdout,…
I'm asking how to mock a class property in a unit test using Python 3. I've tried the following, which makes sense for me following the docs, but it doesn't work:
foo.py:
class Foo():
@property
def bar(self):
return 'foobar'
def…
I have an entry point function call it main on an object that I would like to remain unmocked, since it calls several other methods on the object:
class Thing(object):
def main(self):
self.alpha()
self.bravo()
def…
In brief
When testing a model class in Flask-SqlAlchemy, how can we mock the method .query.filter_by() so as to return the list of mocked model objects?
Full details
Let's say we have a model class as below code
from flask.ext.sqlalchemy import…
Im migrating from PyUnit to Pytest, and I found, that Pytest, unlike PyUnit, does not distinguish fails and errors in test report in quick report while running tests (where dots are printed). How to teach Pytest do do it?
UPDATE
Seems like it is…