Questions tagged [python-unittest]

0 votes
0 replies
How to inject different environment variable in dev, test, prod in Python
I used to work with Flask which offers an easy way to configure the application running in different modes. (dev, test, prod, ...) class BaseCon...
asked 4 months ago
0 votes
0 replies
How can I make this mock database test in Python work?
I am new to writing tests in Python. I am looking to write a test that mocks a database connection to MySQL and makes sure the correct changes wo...
0 votes
2 replies
How to mock a function directly (Python)
We create mock objects and specify the behavior of methods called on them: from unittest.mock import patch, Mock execute = Mock() execute.fetch...
asked 4 months ago
-1 votes
0 replies
custom logging after individual test method in python unittest test case
I have a Unittest test case with few test methods in it. Is it possible to print custom log based on test result after each test method execution...
asked 4 months ago
0 votes
0 replies
Is there any python unittest reporting framework which generates report that can be send via email?
I am building a framework for mobile UI testing using appium and python client. I want a decent test reporting framework using which test reports...
-1 votes
0 replies
Attribute Error while running the unit test in python
I'm running a unit test for my code in python using nose2. I am getting an AttributeError. Equations used: .. math:: \frac{d...
asked 4 months ago
0 votes
1 replies
How to set return value to mock object created from another mock object using unittest?
from connection_util import some_engine class RecommendConversationsUsingOldAPI(BaseResource): def check_entitlement(self,msg_ids,usr_id, m...
asked 4 months ago
0 votes
0 replies
Comparsion between instances of int and Magicmock works in python 2 but raises TypeError in Python3
I am trying to check the response status code after trigerring some API with a POST method, Response status code is of Magicmock instance type, i...
0 votes
1 replies
Not able to mock the database Django chain queries
I am trying to mock the django chain queries. These are 1. MyModel.objects.filter(userId=userId).exists() 2. mrvDb = MyModel.objects.filte...
0 votes
1 replies
How can I remove CLI arguments using argparse so unittest will accept arg list
I'd like to pass my own arguments into files that are setup for unittest. So calling it from the command line like this should work: python Mis...
0 votes
1 replies
How do i test except Errors using side_effect in python unittest mock?
I am a junior developer and trying to write some unittests for our API endpoints. Below is the class that i am testing and the actual test that r...
0 votes
0 replies
Can I pass method as an argument in unittest assertIn?
I am new to unittest and I want know if there any way I can pass methods inside unittest assertIn function as an argument. I want to see if an AP...
asked 4 months ago
-1 votes
0 replies
Mock a database on a specific address
Currently I'm unittesting an API I developped. This API is making some calls in its process to a database, right now my own database. But my data...
asked 4 months ago
0 votes
1 replies
Python mock vs unittest.mock patch
What is the difference between these imports? from mock import patch vs from unittest.mock import patch Are they the same? 0 1 Answers...
3 votes
1 replies
Patching a function inside a package __init__ and use it within a module inside the same package
I am trying to patch an internal package function defined in the __init__.py that is being used by a function inside of a module inside of the sa...
0 votes
0 replies
Can we do cross browser testing using unittest framework?
I am using unittest framework for my script.I want to do cross browser testing with other browsers(other than chrome) also.How can we code in suc...
0 votes
0 replies
How to mock at the descriptor level?
It appears uuid4 is not mocked within the Field descriptor's initializer, but it is within Foo.get_uid. Why is this? # file.py from uuid import...
asked 5 months ago
0 votes
0 replies
How to mock at the descriptor level?
It appears uuid4 is not mocked within the Field descriptor's initializer, but it is within Foo.get_uid. Why is this? # file.py from uuid import...
asked 5 months ago
2 votes
1 replies
How to properly mock private members of a class
I am trying to write some unit tests for a method that depends on another private method. - As shown in the example below: def is_member_of(self...
asked 5 months ago
0 votes
1 replies
How to mock a pika connection for a different module?
I have a class that imports the following module: import pika import pickle from apscheduler.schedulers.background import BackgroundScheduler im...
0 votes
0 replies
How to run debug on a single unittest method in VS code
I am trying to run a single unittest method in Visual Studio Code. However, every time I click on the Debug highlight above my test method name...
3 votes
2 replies
How do I mock a a file IO so that I can override the name attribute in a unit test?
I'm trying to write a unit test mock opening a file and passing it into a function that uses it to dump a JSON object into. How do I create a fak...
asked 5 months ago
0 votes
0 replies
Pycharm's unittest module doesn't load after upgrading
I have upgraded my Pycharm from 2016 to 2018 and now my unit tests do not run. This seems to be down to the unittestpy module not loading: Attri...
1 votes
1 replies
FIle Not Found - Python Unit Test
I have a python code to test. It's a simple code. The folder structure is as follows. . ├── code │ ├── conf.json │ ├── __init__.py │ └── a...
asked 5 months ago
0 votes
0 replies
unittest: How does it actually execute my Test case?
Trying to understand how unittest works, I am looking into its source code and search for the lines which allow the execution of own test cases....
asked 5 months ago