Skip to main content

All Questions

Tagged with
0 votes
0 answers
42 views

How to use python mock with FastAPI unit tests?

I have a FastAPI router file that has a function that calls a utility function in another file that interacts with GCS. I want to mock out the entire gcsutil.create_bucket in an unit test of ...
Crys's user avatar
  • 11
2 votes
0 answers
285 views

How to mock an Enum in pytest globally

I have a trading bot project, let's call it trading_bot. I am using python-binance. I have an enum class CoinName(str, Enum): USDT = "USDT" BTC = "BTC" ETH = "ETH&...
nontrivial's user avatar
0 votes
1 answer
64 views

Mocking or monkey patching a slow loading resource that loads on import

I have 1 file which loads a particular resource ( from a file ) that takes a while to load. I have a function in another file which uses that resource by importing it first. When that resource is ...
Sam's user avatar
  • 309
1 vote
0 answers
30 views

mocking out imported objects in Python

Lets say there is a module headache that defines an object that is then imported and used by code I want to test: # defined in headache/__init__.py problem = Problem() then it's imported by Foo: # ...
solyd's user avatar
  • 792
1 vote
1 answer
26 views

Cannot mock the method in dependency module correctly in Python

Here is my project structure |-- project |-- util.py |-- main.py |-- tests |-- test_main.py In the main.py file I reference the function in util.py from util import rename def ...
hh54188's user avatar
  • 15.7k
0 votes
0 answers
49 views

Why python testing always import the file in another module implicitly

Current I have two files in the same folder, in the source file I import the dlt module # File: pipeline.py import dlt Another is a test file which import nothing from the source file yet: import ...
hh54188's user avatar
  • 15.7k
0 votes
0 answers
241 views

"AssertionError: Expected 'show' to have been called once" when trying to mock plt.show()

I am currently trying to design some tests to run with pytest for a GUI. The GUI has a button that plots a graph on click. I want to make sure the button does indeed generate a graph. At this stage, I ...
DracoArtist's user avatar
0 votes
1 answer
176 views

Mock patching an endpoint unittest that makes several requests to third party

I have a single endpoint written using django ninja. This endpoint executes a crawler that performs several requests. The sequence of requests has 3 different routines depending on whether or not the ...
Gustavo Costa's user avatar
0 votes
0 answers
44 views

Python unittest how to mock function which external function is defined in __init__.py

I would like to test my_func2 that is calling my_func1. I would like to mock my_func1, but I don't know how can I do it when my_func2 is imported in my_package.__init__.py. When I delete that import, ...
sceptre's user avatar
0 votes
0 answers
62 views

Mocking a dictionary upon FastAPI router instantiation

Attempting to write tests for an existing route and running into some roadblocks. I'm trying to mock a dictionary that is loaded when a router is instantiated, but it seems like the @patch'd versions ...
Anthony's user avatar
  • 227
2 votes
1 answer
101 views

Simulate stdout in fake subprocess.Popen

I would like to test a function, which invokes subprocess.Popen and captures stdout. In particular, I need to test stdout content physically captured in a file on disc without ever calling the actual ...
Maxim Ivanov's user avatar
2 votes
1 answer
86 views

Test that a function imported into different namespaces is never called

Suppose I have foo.py def my_func(): print('hello world!') bar.py from foo import my_func I want to write tests to ensure that my_func is never called. I have this: from unittest import mock ...
RuthC's user avatar
  • 3,987
0 votes
1 answer
93 views

Test a function called in else condition

I have written a code where I am calling a function in the else case which returns a string. I have mocked it and asserted it to be called once. But this is failing for some reason. This decreases my ...
vaibhav's user avatar
  • 61
1 vote
1 answer
91 views

Why is my phyton mock only working with a specific way of import?

I have a utils class that besides other stuff has a function to get an id: # utils.py def get_id(): return ... Also, there is another class, lets say its about cars, that uses this function: # ...
ningelsohn's user avatar
0 votes
2 answers
46 views

How do I mock a function called inside the function that I am testing?

My file structure is like this: pytests/ ├── moduleA/ │ ├── functions/ │ │ └── process_moduleA.py │ └── test_process_moduleA.py └── utils/ └── archive.py in process_moduleA, I have ...
Mystique's user avatar

15 30 50 per page
1
2 3 4 5
19