Answer the question
In order to leave comments, you need to log in
How to patch a class with python asynctest?
Help, please, deal with the patch in asynctest
I don’t understand how to change the class. Individual methods are replaced correctly, but the entire class cannot be replaced.
I don’t want to fence a mountain of decorators over each test method.
A working example with replacing methods with an empty function:
class TestGamePrepare(TestCase):
chat_id = -12345667890
admin_id = 987654321
async def setUp(self):
self.game = await get_game(self.chat_id)
@patch('game.Game.delete_messages', pass_func)
async def tearDown(self):
await self.game.cancel()
@patch('game.Game.say', pass_func)
@patch('game.Game.unmute', pass_func)
@patch('game.Game.read_game_settings', pass_func)
@patch('game.Game.delete_messages', pass_func)
async def test_game_prepare(self):
""" Good prepare case """
await self.game.prepare_game(self.admin_id)
self.assertEqual(self.game.mode, GameModes.REGISTRATION)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question