My problem is:
In my following test, everything is working today but not will work tomorrow, I'm a beginner and did try a lot of options, but I failed, I,m trying pass "now" as a parameter but with no success until now.
I have to stop the…
I have a Python class with complicated initialization. I would like to mock the class initialization to avoid writing too much scaffolding code. I want to test its non-mocked method.
A simple example:
class Person:
def __init__(self, x, y, z):
…
I'm using freeze-time to run my python unittest Test cases.
A dummy test case:
@freeze_time('2020-01-01')
def test_something(self):
expected_output = {'time': '2020-01-01'}
output = call_tested_code()
self.assertEqual(expected_output,…
I am trying to save response from an HTTP request in a global variable using globals() in python so that I can use that data later.
def request_agent(agent_name, urL):
r = requests.get(urL)
data = r.json()
globals()[agent_name] =…
I've moved recently from Python 2.7 to Python 3.8. There's a strange new phenomenon when running the tests, that can be reproduced with this simple example:
from django.test import TestCase
from users.models import User
class TestWTF(TestCase):
…
This question is related to Relative imports with unittest in Python but I would like to specifically ask about the importance of how unittest handles/modifies imports.
Say I have a package structure:
containing_folder/
project/
…
I am struggling to mock a method inside another method i.e Let's say I have 2 classes A, B as follows:
class A:
def method_A(self):
return "Hi"
class B:
def method_B(self):
instance_A = A()
result =…
I am implementing unit test on one of the classes of my project. The method that I want to test is queryCfsNoteVariations:
class PdfRaportDaoImpl:
def queryCfsNoteVariations(self, reportId):
sql = """
select v.* from…
I have the following unit test written in python,When i try to run this code, i am getting an attribute error in the console that
AttributeError: 'testLogin' object has no attribute 'lp' I am very new to python and i would like to get some insight…
I am trying to mock an existing object from another library's class for unit tests with pytest.
However, the attributes (not methods) from the other library are mostly set during runtime.
What I want to achieve
Get all the benefits of mocking the…
I am trying to write a python test that involves testing if the environment variables provided are valid. I am passing the environment variables as follows
env = EnvironmentVarGuard() env.set('GOOGLE_CREDENTIALS', GOOGLE_CREDENTIALS)
The…
My goal is to create a GitHub repo with a module and unit tests that other developers can check out and work on, including running the unit tests. This module does PDF manipulation, so I need to provide some sample PDFs to test, plus paths for…
I'm writing unit tests with Python for a project and recently encountered a problem with the decorator @patch. I have the following method which I need to test
def _read_from_disk(self, excel_kwargs):
"""
Read excel file from disk…
I have a test file which run some binary executable and check the output. The test looks like this:
#! /usr/bin/env python
from subprocess import Popen, PIPE
import unittest
import sys
class MyTest(unittest.TestCase):
PATH = './app'
def…
This python code file works perfectly. But when I add either of the commented imports, the vscode test feature gives "No tests discovered, please check the configuration settings for the tests." No other errors.
# import boto3
# import…