I would like to unit test a piece of code where I am fetching results from a SQL server database and then loop through using fetchmany . I am not using fetchall as I expect the resultset to be huge.
However, mocking it is causing an infinite loop as…
How can I test the constructor of my class, and subsequent objects created by it? I tried different combinations, and patching the __init__ function of MyClass, but I get different errors depending on what I try, for example __init__() should return…
I have an endpoint on my localhost to get time from different time zones. I type the time zone code in the URL and it shows the time for that time zone. This program uses an external API to get the time.
I need to mock this call to the external API…
I'm running my first unit test on this function contained in a module called updater:
import logging
import subprocess
logger = logging.getLogger(__name__)
def update_oncourt():
return_code = subprocess.run(['perl',…
I have a method that returns a dictionary and that dictionary contains email specific confidential information like address,recipient, token etc.
For sending an email, I need to access a rest URL and send the data along with confidential…
How can I document my tests, only my tests?
I document my unittest with Sphinx.
My setup is as followed:
class MyTestWrapper1(unittest.Testcase)
def test_general_setup()
class MyTestWrapper2(MyTestWrapper1)
def…
I use PyCharm to right click Run 'hello ' or use shell to run python hello.py ,both return below error :
if __name__ == "__main__":
^
IndentationError: expected an indented block
below code is copied from…
I am unittesting validations and checkconstraints on my model:
class MyModel(models.Model):
title = models.CharField()
class Meta:
models.CheckConstraint(
check=~Q(title='Word'),
name='title_cannot_be_word'
…
I am using postgreSQL 12.
I have the following models:
class Publication(models.Model):
title = models.CharField(max_length=30)
class Article(models.Model):
headline = models.CharField(max_length=100)
publications =…
I have a project structure something like this. I want to write a test which programmatically change version variable in myPackage/version.py and write a test in tests/unit/test_release.py.
├── myPackage
│ ├── __init__.py
│ ├── root.py
│ └──…
I have come up with this issue, where by following the instructions found in the coverage.py page I end up getting the report on the test files themselves instead of the application files. I am referring to a Flask application, using unittest as a…
I am trying to patch a decorator. The testing framework that I am using is pytest. I am able to patch it successfully. However, the patch remains through out the test session, and thus I am not able to test the decorator itself.
Here is a sample…
[as I created test suite and generate a test report using HTMLTestRunner (Also modified little bit by me) single test run twice.]
for that code (test suite) is:
import os
import time
import unittest
from xyz.base import log
from builtins import…
I have a unittest test case in my app which needs to be py2 and py3 compatible.
class MyTest(TestCase):
def test_pep3102(self):
def fn(a, b, *, d):
pass
# do something
# assert
This test case works fine with py3…
I have been wondering about this behaviour when replacing a class method I observe in Python 3.8 and concluded I do not understand it. I suspect it may have something to do with loosing the @classmethod decorator or something similar, but am at a…