Answer the question
In order to leave comments, you need to log in
Why doesn't mock.side_effect work?
# bot/bot.py
class Bot:
def check(self):
if not self._check_proxy():
raise ValueError('Proxy is invalid!')
# bot/management/commands/check_bot.py
from bot.bot import Bot
bot = Bot()
class Command(BaseCommand):
def handle(self, *args, **options):
print(type(bot.check))
bot.check()
# tests/test_commands.py
class TestCheckCmd(TestCase):
@patch('bot.bot.Bot.check')
def test_check_bot_fail(self, mock_check):
mock_check.side_effect = ValueError
with self.assertRaises(ValueError) as exc:
call_command('check_bot')
<class 'unittest.mock.MagicMock'>
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