python check if a method is called without mocking it away

You can set the Mock.side_effect to be the original method. from unittest.mock import MagicMock class A(): def tmp(self): print(“hi”) def b(a): a.tmp() a = A() a.tmp = MagicMock(side_effect=a.tmp) b(a) a.tmp.assert_called() When side_effect is a function (or a bound method in this case, which is a kind of function), calling the Mock will also call the … Read more

How to hyperlink in a Jupyter notebook?

To create a internal clickable link in the same notebook: Step 1: Create link [To some Internal Section](#section_id) Step 2: Create destination <a id=’section_id’></a> To create link in one notebook and destination in another notebook. Step 1: Create link [To Some Internal Section](another_notebook.ipynb#section_id2) Step 2: Create Destination <a id=’section_id2′></a> If the notebook is inside a … Read more

Python3 & PyCharm – Debug logging levels in run/debug

The problem has nothing to do with PyCharm, but with how logging configuration works. If you try to write the code you have shown in a normal python interactive session you get the same output: >>> import logging >>> logger = logging.getLogger(‘tipper’) >>> logger.setLevel(logging.DEBUG) >>> logger.debug(‘debug message’) >>> logger.info(‘info message’) >>> logger.warn(‘warn message’) warn message … Read more

Mock exception raised in function using Pytest

You can mock error raising via side_effect parameter: Alternatively side_effect can be an exception class or instance. In this case the exception will be raised when the mock is called. In your case, this can be used like this (assuming call_api is defined in module foo): import pytest from unittest.mock import patch def test_api(): with … Read more

Can we send message to user in slack using python script?

Yes,this can be done. Instead of “#channel_name” use “@user” in the API. The user will receive the message from slackbot as we are using API and not a direct message from any other user. And if you want to post to that user as the authenticated user, use as_user= true. slack.chat.post_message(‘@to_user’,msg,username=”@from_user”) More details are at … Read more

Multiple inheritance metaclass conflict

The problem in your case is that the classes you try to inherit from have different metaclasses: >>> type(QStandardItem) <class ‘sip.wrappertype’> >>> type(ConfigParser) <class ‘abc.ABCMeta’> Therefore python can’t decide which should be the metaclass for the newly created class. In this case, it would have to be a class inheriting from both sip.wrappertype (or PyQt5.QtCore.pyqtWrapperType … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)