Skip to main content
Stack Overflow
  1. About
  2. For Teams
Filter by
Sorted by
Tagged with
1 vote
1 answer
124 views

Sometimes when I develop by TDD (Test Driven Development) I need to test the calling order of some class methods. In general I write Python code so I'll show the last test case that I have just ...
0 votes
2 answers
585 views

Given the doc for assert_any_call I have a log statement I want to assert against ... logger.warning('Backup quantity is 0, supplied uuids %s, matched machines: %s', uuids, machines) ... see the ...
0 votes
1 answer
70 views

I do not manage to do some basic assert_called() in a class where some methods are internally calling other methods. Example code: from unittest.mock import Mock class Foo: def print1(self) -> ...
0 votes
2 answers
307 views

I want to write a unit test to a function which instantiates a dataclass twice followed by calling its method. However, the actual calls of the instantiation includes the calling of the method. This ...
0 votes
1 answer
189 views

I have a function I need to test example: async def post(self): #bunch of calls try: var = await another_func(x, y) #returns int value if var != 1: raise exception ...
1 vote
1 answer
191 views

I am aware the basics of the path for mock.path, but it's increasingly difficult to work out the correct path when the object is encapsulated by layers of dynamic construction, eg. django viewflow how ...
2 votes
0 answers
92 views

With this class: class Something(): def __init__(self, name) -> None: self.name=name @property def value(self): # In real life, something long and complicated ...
0 votes
1 answer
35 views

I am aware of the importance of path to mock as illustrated here, but consider this Django scenario models.py class Proxmox(Model): @property def api(self, ...): .... tasks.py def ...
James Lin's user avatar
  • 26.8k
1 vote
1 answer
135 views

I need to test a function that uses a lot of legacy code that I can't touch now. I patched the legacy class (LegacyClass) with the @patch decorator on my test class. The legacy class has a method ...
2 votes
2 answers
883 views

I have a structure like so: mod1 ├── mod2 │ ├── __init__.py │ └── utils.py └── tests └── test_utils.py where __init__.py: CONST = -1 utils.py: from mod1.mod2 import CONST def mod_function(...
alex's user avatar
  • 11.4k
0 votes
1 answer
748 views

tl;dr how to have a mock.patch for a @classmethod last an entire test session instead of only within with scope or function scope? I want to mock patch a class method. However, I would like to run ...
0 votes
1 answer
32 views

Say I want to test my calls Greeter which depends a 3rd party class Foo which in turn depends on another class Bar. I need to mock Foo, but how do I set up and verify the chained call self.foo.get_bar(...
Dagang Wei's user avatar
  • 26.9k
-2 votes
1 answer
99 views

I have code like this: a.py from app.cache import Cache my_cache = Cache(cache_prefix='xxxxx') b.py from a import my_cache class MyApp: def run_app(): my_cache.get(1,2) test_b.py ...
0 votes
1 answer
102 views

I am trying to mock a property and would like to control the return value of the property according to other state in the object. A small representative example looks like this import datetime from ...
1 vote
1 answer
183 views

I'm having a view in which there is a method called can_upload_file that makes external calls. This method is called from view's post (create) method. So, in my unit test I'm trying to test the post ...

15 30 50 per page
1
2 3 4 5
...
32

AltStyle によって変換されたページ (->オリジナル) /